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.

896 lines
29KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2016 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 doc/GPL.txt file.
  16. */
  17. #include "CarlaUtils.h"
  18. #include "CarlaNative.h"
  19. #include "CarlaBackendUtils.hpp"
  20. #include "CarlaLv2Utils.hpp"
  21. #include "CarlaPipeUtils.hpp"
  22. #include "CarlaThread.hpp"
  23. #include "LinkedList.hpp"
  24. #ifndef CARLA_UTILS_CACHED_PLUGINS_ONLY
  25. # include "juce_audio_formats/juce_audio_formats.h"
  26. # ifdef HAVE_X11
  27. # include <X11/Xlib.h>
  28. # endif
  29. #endif
  30. #ifdef CARLA_OS_MAC
  31. # include "juce_audio_processors/juce_audio_processors.h"
  32. #endif
  33. #include "../native-plugins/_data.cpp"
  34. namespace CB = CarlaBackend;
  35. static const char* const gNullCharPtr = "";
  36. #ifdef CARLA_OS_MAC
  37. static juce::StringArray gCachedAuPluginResults;
  38. #endif
  39. // -------------------------------------------------------------------------------------------------------------------
  40. _CarlaCachedPluginInfo::_CarlaCachedPluginInfo() noexcept
  41. : category(CB::PLUGIN_CATEGORY_NONE),
  42. hints(0x0),
  43. audioIns(0),
  44. audioOuts(0),
  45. midiIns(0),
  46. midiOuts(0),
  47. parameterIns(0),
  48. parameterOuts(0),
  49. name(gNullCharPtr),
  50. label(gNullCharPtr),
  51. maker(gNullCharPtr),
  52. copyright(gNullCharPtr) {}
  53. // -------------------------------------------------------------------------------------------------------------------
  54. uint carla_get_cached_plugin_count(CB::PluginType ptype, const char* pluginPath)
  55. {
  56. CARLA_SAFE_ASSERT_RETURN(ptype == CB::PLUGIN_INTERNAL || ptype == CB::PLUGIN_LV2 || ptype == CB::PLUGIN_AU, 0);
  57. carla_debug("carla_get_cached_plugin_count(%i:%s)", ptype, CB::PluginType2Str(ptype));
  58. switch (ptype)
  59. {
  60. case CB::PLUGIN_INTERNAL: {
  61. uint32_t count = 0;
  62. carla_get_native_plugins_data(&count);
  63. return count;
  64. }
  65. case CB::PLUGIN_LV2: {
  66. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  67. lv2World.initIfNeeded(pluginPath);
  68. return lv2World.getPluginCount();
  69. }
  70. case CB::PLUGIN_AU: {
  71. #ifdef CARLA_OS_MAC
  72. static bool initiated = false;
  73. if (! initiated)
  74. {
  75. using namespace juce;
  76. initiated = true;
  77. AudioUnitPluginFormat auFormat;
  78. gCachedAuPluginResults = auFormat.searchPathsForPlugins(juce::FileSearchPath(), false, false);
  79. }
  80. return static_cast<uint>(gCachedAuPluginResults.size());
  81. #else
  82. return 0;
  83. #endif
  84. }
  85. default:
  86. return 0;
  87. }
  88. }
  89. const CarlaCachedPluginInfo* carla_get_cached_plugin_info(CB::PluginType ptype, uint index)
  90. {
  91. carla_debug("carla_get_cached_plugin_info(%i:%s, %i)", ptype, CB::PluginType2Str(ptype), index);
  92. static CarlaCachedPluginInfo info;
  93. switch (ptype)
  94. {
  95. case CB::PLUGIN_INTERNAL: {
  96. uint32_t count = 0;
  97. const NativePluginDescriptor* const descs(carla_get_native_plugins_data(&count));
  98. CARLA_SAFE_ASSERT_BREAK(index < count);
  99. CARLA_SAFE_ASSERT_BREAK(descs != nullptr);
  100. const NativePluginDescriptor& desc(descs[index]);
  101. info.category = static_cast<CB::PluginCategory>(desc.category);
  102. info.hints = 0x0;
  103. if (desc.hints & NATIVE_PLUGIN_IS_RTSAFE)
  104. info.hints |= CB::PLUGIN_IS_RTSAFE;
  105. if (desc.hints & NATIVE_PLUGIN_IS_SYNTH)
  106. info.hints |= CB::PLUGIN_IS_SYNTH;
  107. if (desc.hints & NATIVE_PLUGIN_HAS_UI)
  108. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  109. if (desc.hints & NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS)
  110. info.hints |= CB::PLUGIN_NEEDS_FIXED_BUFFERS;
  111. if (desc.hints & NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD)
  112. info.hints |= CB::PLUGIN_NEEDS_UI_MAIN_THREAD;
  113. if (desc.hints & NATIVE_PLUGIN_USES_MULTI_PROGS)
  114. info.hints |= CB::PLUGIN_USES_MULTI_PROGS;
  115. info.audioIns = desc.audioIns;
  116. info.audioOuts = desc.audioOuts;
  117. info.midiIns = desc.midiIns;
  118. info.midiOuts = desc.midiOuts;
  119. info.parameterIns = desc.paramIns;
  120. info.parameterOuts = desc.paramOuts;
  121. info.name = desc.name;
  122. info.label = desc.label;
  123. info.maker = desc.maker;
  124. info.copyright = desc.copyright;
  125. return &info;
  126. }
  127. case CB::PLUGIN_LV2: {
  128. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  129. const LilvPlugin* const cPlugin(lv2World.getPluginFromIndex(index));
  130. CARLA_SAFE_ASSERT_BREAK(cPlugin != nullptr);
  131. Lilv::Plugin lilvPlugin(cPlugin);
  132. CARLA_SAFE_ASSERT_BREAK(lilvPlugin.get_uri().is_uri());
  133. carla_stdout("Filling info for LV2 with URI '%s'", lilvPlugin.get_uri().as_uri());
  134. // features
  135. info.hints = 0x0;
  136. if (lilvPlugin.get_uis().size() > 0 || lilvPlugin.get_modgui_resources_directory().as_uri() != nullptr)
  137. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  138. {
  139. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  140. LILV_FOREACH(nodes, it, lilvFeatureNodes)
  141. {
  142. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it));
  143. const char* const featureURI(lilvFeatureNode.as_uri());
  144. CARLA_SAFE_ASSERT_CONTINUE(featureURI != nullptr);
  145. if (std::strcmp(featureURI, LV2_CORE__hardRTCapable) == 0)
  146. info.hints |= CB::PLUGIN_IS_RTSAFE;
  147. }
  148. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodes.me));
  149. }
  150. // category
  151. info.category = CB::PLUGIN_CATEGORY_NONE;
  152. {
  153. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  154. if (typeNodes.size() > 0)
  155. {
  156. if (typeNodes.contains(lv2World.class_allpass))
  157. info.category = CB::PLUGIN_CATEGORY_FILTER;
  158. if (typeNodes.contains(lv2World.class_amplifier))
  159. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  160. if (typeNodes.contains(lv2World.class_analyzer))
  161. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  162. if (typeNodes.contains(lv2World.class_bandpass))
  163. info.category = CB::PLUGIN_CATEGORY_FILTER;
  164. if (typeNodes.contains(lv2World.class_chorus))
  165. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  166. if (typeNodes.contains(lv2World.class_comb))
  167. info.category = CB::PLUGIN_CATEGORY_FILTER;
  168. if (typeNodes.contains(lv2World.class_compressor))
  169. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  170. if (typeNodes.contains(lv2World.class_constant))
  171. info.category = CB::PLUGIN_CATEGORY_OTHER;
  172. if (typeNodes.contains(lv2World.class_converter))
  173. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  174. if (typeNodes.contains(lv2World.class_delay))
  175. info.category = CB::PLUGIN_CATEGORY_DELAY;
  176. if (typeNodes.contains(lv2World.class_distortion))
  177. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  178. if (typeNodes.contains(lv2World.class_dynamics))
  179. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  180. if (typeNodes.contains(lv2World.class_eq))
  181. info.category = CB::PLUGIN_CATEGORY_EQ;
  182. if (typeNodes.contains(lv2World.class_envelope))
  183. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  184. if (typeNodes.contains(lv2World.class_expander))
  185. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  186. if (typeNodes.contains(lv2World.class_filter))
  187. info.category = CB::PLUGIN_CATEGORY_FILTER;
  188. if (typeNodes.contains(lv2World.class_flanger))
  189. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  190. if (typeNodes.contains(lv2World.class_function))
  191. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  192. if (typeNodes.contains(lv2World.class_gate))
  193. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  194. if (typeNodes.contains(lv2World.class_generator))
  195. info.category = CB::PLUGIN_CATEGORY_OTHER;
  196. if (typeNodes.contains(lv2World.class_highpass))
  197. info.category = CB::PLUGIN_CATEGORY_FILTER;
  198. if (typeNodes.contains(lv2World.class_limiter))
  199. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  200. if (typeNodes.contains(lv2World.class_lowpass))
  201. info.category = CB::PLUGIN_CATEGORY_FILTER;
  202. if (typeNodes.contains(lv2World.class_mixer))
  203. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  204. if (typeNodes.contains(lv2World.class_modulator))
  205. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  206. if (typeNodes.contains(lv2World.class_multiEQ))
  207. info.category = CB::PLUGIN_CATEGORY_EQ;
  208. if (typeNodes.contains(lv2World.class_oscillator))
  209. info.category = CB::PLUGIN_CATEGORY_OTHER;
  210. if (typeNodes.contains(lv2World.class_paraEQ))
  211. info.category = CB::PLUGIN_CATEGORY_EQ;
  212. if (typeNodes.contains(lv2World.class_phaser))
  213. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  214. if (typeNodes.contains(lv2World.class_pitch))
  215. info.category = CB::PLUGIN_CATEGORY_OTHER;
  216. if (typeNodes.contains(lv2World.class_reverb))
  217. info.category = CB::PLUGIN_CATEGORY_DELAY;
  218. if (typeNodes.contains(lv2World.class_simulator))
  219. info.category = CB::PLUGIN_CATEGORY_OTHER;
  220. if (typeNodes.contains(lv2World.class_spatial))
  221. info.category = CB::PLUGIN_CATEGORY_OTHER;
  222. if (typeNodes.contains(lv2World.class_spectral))
  223. info.category = CB::PLUGIN_CATEGORY_OTHER;
  224. if (typeNodes.contains(lv2World.class_utility))
  225. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  226. if (typeNodes.contains(lv2World.class_waveshaper))
  227. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  228. if (typeNodes.contains(lv2World.class_instrument))
  229. {
  230. info.category = CB::PLUGIN_CATEGORY_SYNTH;
  231. info.hints |= CB::PLUGIN_IS_SYNTH;
  232. }
  233. }
  234. lilv_nodes_free(const_cast<LilvNodes*>(typeNodes.me));
  235. }
  236. // number data
  237. info.audioIns = 0;
  238. info.audioOuts = 0;
  239. info.midiIns = 0;
  240. info.midiOuts = 0;
  241. info.parameterIns = 0;
  242. info.parameterOuts = 0;
  243. for (uint i=0, count=lilvPlugin.get_num_ports(); i<count; ++i)
  244. {
  245. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(i));
  246. bool isInput;
  247. /**/ if (lilvPort.is_a(lv2World.port_input))
  248. isInput = true;
  249. else if (lilvPort.is_a(lv2World.port_output))
  250. isInput = false;
  251. else
  252. continue;
  253. /**/ if (lilvPort.is_a(lv2World.port_control))
  254. {
  255. // skip some control ports
  256. if (lilvPort.has_property(lv2World.reportsLatency))
  257. continue;
  258. if (LilvNode* const designationNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.designation.me))
  259. {
  260. bool skip = false;
  261. if (const char* const designation = lilv_node_as_string(designationNode))
  262. {
  263. /**/ if (std::strcmp(designation, LV2_CORE__control) == 0)
  264. skip = true;
  265. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  266. skip = true;
  267. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  268. skip = true;
  269. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  270. skip = true;
  271. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  272. skip = true;
  273. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  274. skip = true;
  275. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  276. skip = true;
  277. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  278. skip = true;
  279. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  280. skip = true;
  281. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  282. skip = true;
  283. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  284. skip = true;
  285. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  286. skip = true;
  287. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  288. skip = true;
  289. else if (std::strcmp(designation, LV2_KXSTUDIO_PROPERTIES__TimePositionTicksPerBeat) == 0)
  290. skip = true;
  291. }
  292. lilv_node_free(designationNode);
  293. if (skip)
  294. continue;
  295. }
  296. if (isInput)
  297. ++(info.parameterIns);
  298. else
  299. ++(info.parameterOuts);
  300. }
  301. else if (lilvPort.is_a(lv2World.port_audio))
  302. {
  303. if (isInput)
  304. ++(info.audioIns);
  305. else
  306. ++(info.audioOuts);
  307. }
  308. else if (lilvPort.is_a(lv2World.port_cv))
  309. {
  310. }
  311. else if (lilvPort.is_a(lv2World.port_atom))
  312. {
  313. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  314. for (LilvIter *it = lilv_nodes_begin(supportNodes.me); ! lilv_nodes_is_end(supportNodes.me, it); it = lilv_nodes_next(supportNodes.me, it))
  315. {
  316. const Lilv::Node node(lilv_nodes_get(supportNodes.me, it));
  317. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  318. if (node.equals(lv2World.midi_event))
  319. {
  320. if (isInput)
  321. ++(info.midiIns);
  322. else
  323. ++(info.midiOuts);
  324. }
  325. }
  326. lilv_nodes_free(const_cast<LilvNodes*>(supportNodes.me));
  327. }
  328. else if (lilvPort.is_a(lv2World.port_event))
  329. {
  330. if (lilvPort.supports_event(lv2World.midi_event))
  331. {
  332. if (isInput)
  333. ++(info.midiIns);
  334. else
  335. ++(info.midiOuts);
  336. }
  337. }
  338. else if (lilvPort.is_a(lv2World.port_midi))
  339. {
  340. if (isInput)
  341. ++(info.midiIns);
  342. else
  343. ++(info.midiOuts);
  344. }
  345. }
  346. // text data
  347. static CarlaString suri, sname, smaker, slicense;
  348. suri.clear(); sname.clear(); smaker.clear(); slicense.clear();
  349. suri = lilvPlugin.get_uri().as_uri();
  350. if (LilvNode* const nameNode = lilv_plugin_get_name(lilvPlugin.me))
  351. {
  352. if (const char* const name = lilv_node_as_string(nameNode))
  353. sname = name;
  354. lilv_node_free(nameNode);
  355. }
  356. if (const char* const author = lilvPlugin.get_author_name().as_string())
  357. smaker = author;
  358. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  359. if (licenseNodes.size() > 0)
  360. {
  361. if (const char* const license = licenseNodes.get_first().as_string())
  362. slicense = license;
  363. }
  364. lilv_nodes_free(const_cast<LilvNodes*>(licenseNodes.me));
  365. info.name = sname;
  366. info.label = suri;
  367. info.maker = smaker;
  368. info.copyright = slicense;
  369. return &info;
  370. }
  371. case CB::PLUGIN_AU: {
  372. #ifdef CARLA_OS_MAC
  373. const int indexi(static_cast<int>(index));
  374. CARLA_SAFE_ASSERT_BREAK(indexi < gCachedAuPluginResults.size());
  375. using namespace juce;
  376. String pluginId(gCachedAuPluginResults[indexi]);
  377. OwnedArray<PluginDescription> results;
  378. AudioUnitPluginFormat auFormat;
  379. auFormat.findAllTypesForFile(results, pluginId);
  380. CARLA_SAFE_ASSERT_BREAK(results.size() > 0);
  381. CARLA_SAFE_ASSERT(results.size() == 1);
  382. PluginDescription* const desc(results[0]);
  383. CARLA_SAFE_ASSERT_BREAK(desc != nullptr);
  384. info.category = CB::getPluginCategoryFromName(desc->category.toRawUTF8());
  385. info.hints = 0x0;
  386. if (desc->isInstrument)
  387. info.hints |= CB::PLUGIN_IS_SYNTH;
  388. if (true)
  389. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  390. info.audioIns = static_cast<uint32_t>(desc->numInputChannels);
  391. info.audioOuts = static_cast<uint32_t>(desc->numOutputChannels);
  392. info.midiIns = desc->isInstrument ? 1 : 0;
  393. info.midiOuts = 0;
  394. info.parameterIns = 0;
  395. info.parameterOuts = 0;
  396. static CarlaString sname, slabel, smaker;
  397. sname = desc->name.toRawUTF8();
  398. slabel = desc->fileOrIdentifier.toRawUTF8();
  399. smaker = desc->manufacturerName.toRawUTF8();
  400. info.name = sname;
  401. info.label = slabel;
  402. info.maker = smaker;
  403. info.copyright = gNullCharPtr;
  404. return &info;
  405. #else
  406. break;
  407. #endif
  408. }
  409. default:
  410. break;
  411. }
  412. info.category = CB::PLUGIN_CATEGORY_NONE;
  413. info.hints = 0x0;
  414. info.audioIns = 0;
  415. info.audioOuts = 0;
  416. info.midiIns = 0;
  417. info.midiOuts = 0;
  418. info.parameterIns = 0;
  419. info.parameterOuts = 0;
  420. info.name = gNullCharPtr;
  421. info.label = gNullCharPtr;
  422. info.maker = gNullCharPtr;
  423. info.copyright = gNullCharPtr;
  424. return &info;
  425. }
  426. #ifndef CARLA_UTILS_CACHED_PLUGINS_ONLY
  427. // -------------------------------------------------------------------------------------------------------------------
  428. const char* carla_get_complete_license_text()
  429. {
  430. carla_debug("carla_get_complete_license_text()");
  431. static CarlaString retText;
  432. if (retText.isEmpty())
  433. {
  434. retText =
  435. "<p>This current Carla build is using the following features and 3rd-party code:</p>"
  436. "<ul>"
  437. #if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN) || ! defined(VESTIGE_HEADER)
  438. # define LS_NOTE_NO "2"
  439. #else
  440. # define LS_NOTE_NO "1"
  441. #endif
  442. // Plugin formats
  443. "<li>LADSPA plugin support</li>"
  444. "<li>DSSI plugin support</li>"
  445. "<li>LV2 plugin support</li>"
  446. #ifdef VESTIGE_HEADER
  447. "<li>VST2 plugin support using VeSTige header by Javier Serrano Polo</li>"
  448. #else
  449. "<li>VST2 plugin support using official VST SDK 2.4 [1]</li>"
  450. #endif
  451. #if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
  452. "<li>VST3 plugin support using official VST SDK 3.6 [1]</li>"
  453. #endif
  454. #ifdef CARLA_OS_MAC
  455. "<li>AU plugin support</li>"
  456. #endif
  457. // Sample kit libraries
  458. #ifdef HAVE_FLUIDSYNTH
  459. "<li>FluidSynth library for SF2 support</li>"
  460. #endif
  461. #ifdef HAVE_LINUXSAMPLER
  462. "<li>LinuxSampler library for GIG and SFZ support [" LS_NOTE_NO "]</li>"
  463. #endif
  464. // misc libs
  465. "<li>base64 utilities based on code by Ren\u00E9 Nyffenegger</li>"
  466. "<li>liblo library for OSC support</li>"
  467. "<li>rtmempool library by Nedko Arnaudov"
  468. "<li>serd, sord, sratom and lilv libraries for LV2 discovery</li>"
  469. #if ! (defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN))
  470. "<li>RtAudio and RtMidi libraries for extra Audio and MIDI support</li>"
  471. #endif
  472. // Internal plugins
  473. #ifdef HAVE_EXPERIMENTAL_PLUGINS
  474. "<li>AT1, BLS1 and REV1 plugin code by Fons Adriaensen</li>"
  475. #endif
  476. "<li>MIDI Sequencer UI code by Perry Nguyen</li>"
  477. "<li>Nekobi plugin code based on nekobee by Sean Bolton and others</li>"
  478. "<li>VectorJuice and WobbleJuice plugin code by Andre Sklenar</li>"
  479. #ifdef HAVE_ZYN_DEPS
  480. "<li>ZynAddSubFX plugin code by Mark McCurry and Nasca Octavian Paul</li>"
  481. #endif
  482. // end
  483. "</ul>"
  484. "<p>"
  485. #if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN) || ! defined(VESTIGE_HEADER)
  486. // Required by VST SDK
  487. "&nbsp;[1] Trademark of Steinberg Media Technologies GmbH.<br/>"
  488. #endif
  489. #ifdef HAVE_LINUXSAMPLER
  490. // LinuxSampler GPL exception
  491. "&nbsp;[" LS_NOTE_NO "] Using LinuxSampler code in commercial hardware or software products is not allowed without prior written authorization by the authors."
  492. #endif
  493. "</p>"
  494. ;
  495. }
  496. return retText;
  497. }
  498. const char* carla_get_juce_version()
  499. {
  500. carla_debug("carla_get_juce_version()");
  501. static CarlaString retVersion;
  502. if (retVersion.isEmpty())
  503. {
  504. if (const char* const version = juce::SystemStats::getJUCEVersion().toRawUTF8())
  505. retVersion = version+6;
  506. else
  507. retVersion = "4.0";
  508. }
  509. return retVersion;
  510. }
  511. const char* carla_get_supported_file_extensions()
  512. {
  513. carla_debug("carla_get_supported_file_extensions()");
  514. static CarlaString retText;
  515. if (retText.isEmpty())
  516. {
  517. retText =
  518. // Base types
  519. "*.carxp;*.carxs"
  520. // MIDI files
  521. ";*.mid;*.midi"
  522. #ifdef HAVE_FLUIDSYNTH
  523. // fluidsynth (sf2)
  524. ";*.sf2"
  525. #endif
  526. #ifdef HAVE_LINUXSAMPLER
  527. // linuxsampler (gig and sfz)
  528. ";*.gig;*.sfz"
  529. #endif
  530. #ifdef HAVE_ZYN_DEPS
  531. // zynaddsubfx presets
  532. ";*.xmz;*.xiz"
  533. #endif
  534. ;
  535. // Audio files
  536. {
  537. using namespace juce;
  538. AudioFormatManager afm;
  539. afm.registerBasicFormats();
  540. String juceFormats;
  541. for (AudioFormat **it=afm.begin(), **end=afm.end(); it != end; ++it)
  542. {
  543. const StringArray& exts((*it)->getFileExtensions());
  544. for (String *eit=exts.begin(), *eend=exts.end(); eit != eend; ++eit)
  545. juceFormats += String(";*" + (*eit)).toRawUTF8();
  546. }
  547. retText += juceFormats.toRawUTF8();
  548. }
  549. }
  550. return retText;
  551. }
  552. // -------------------------------------------------------------------------------------------------------------------
  553. void carla_fflush(bool err)
  554. {
  555. std::fflush(err ? stderr : stdout);
  556. }
  557. void carla_fputs(bool err, const char* string)
  558. {
  559. std::fputs(string, err ? stderr : stdout);
  560. }
  561. void carla_set_process_name(const char* name)
  562. {
  563. carla_debug("carla_set_process_name(\"%s\")", name);
  564. CarlaThread::setCurrentThreadName(name);
  565. juce::Thread::setCurrentThreadName(name);
  566. }
  567. // -------------------------------------------------------------------------------------------------------------------
  568. class CarlaPipeClientPlugin : public CarlaPipeClient
  569. {
  570. public:
  571. CarlaPipeClientPlugin(const CarlaPipeCallbackFunc callbackFunc, void* const callbackPtr) noexcept
  572. : CarlaPipeClient(),
  573. fCallbackFunc(callbackFunc),
  574. fCallbackPtr(callbackPtr)
  575. {
  576. CARLA_SAFE_ASSERT(fCallbackFunc != nullptr);
  577. }
  578. const char* readlineblock(const uint timeout) noexcept
  579. {
  580. return CarlaPipeClient::_readlineblock(timeout);
  581. }
  582. bool msgReceived(const char* const msg) noexcept
  583. {
  584. if (fCallbackFunc != nullptr)
  585. {
  586. try {
  587. fCallbackFunc(fCallbackPtr, msg);
  588. } CARLA_SAFE_EXCEPTION("msgReceived");
  589. }
  590. return true;
  591. }
  592. private:
  593. const CarlaPipeCallbackFunc fCallbackFunc;
  594. void* const fCallbackPtr;
  595. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPipeClientPlugin)
  596. };
  597. CarlaPipeClientHandle carla_pipe_client_new(const char* argv[], CarlaPipeCallbackFunc callbackFunc, void* callbackPtr)
  598. {
  599. carla_debug("carla_pipe_client_new(%p, %p, %p)", argv, callbackFunc, callbackPtr);
  600. CarlaPipeClientPlugin* const pipe(new CarlaPipeClientPlugin(callbackFunc, callbackPtr));
  601. if (! pipe->initPipeClient(argv))
  602. {
  603. delete pipe;
  604. return nullptr;
  605. }
  606. return pipe;
  607. }
  608. void carla_pipe_client_idle(CarlaPipeClientHandle handle)
  609. {
  610. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  611. ((CarlaPipeClientPlugin*)handle)->idlePipe();
  612. }
  613. bool carla_pipe_client_is_running(CarlaPipeClientHandle handle)
  614. {
  615. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  616. return ((CarlaPipeClientPlugin*)handle)->isPipeRunning();
  617. }
  618. void carla_pipe_client_lock(CarlaPipeClientHandle handle)
  619. {
  620. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  621. return ((CarlaPipeClientPlugin*)handle)->lockPipe();
  622. }
  623. void carla_pipe_client_unlock(CarlaPipeClientHandle handle)
  624. {
  625. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  626. return ((CarlaPipeClientPlugin*)handle)->unlockPipe();
  627. }
  628. const char* carla_pipe_client_readlineblock(CarlaPipeClientHandle handle, uint timeout)
  629. {
  630. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, nullptr);
  631. return ((CarlaPipeClientPlugin*)handle)->readlineblock(timeout);
  632. }
  633. bool carla_pipe_client_write_msg(CarlaPipeClientHandle handle, const char* msg)
  634. {
  635. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  636. return ((CarlaPipeClientPlugin*)handle)->writeMessage(msg);
  637. }
  638. bool carla_pipe_client_write_and_fix_msg(CarlaPipeClientHandle handle, const char* msg)
  639. {
  640. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  641. return ((CarlaPipeClientPlugin*)handle)->writeAndFixMessage(msg);
  642. }
  643. bool carla_pipe_client_flush(CarlaPipeClientHandle handle)
  644. {
  645. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  646. return ((CarlaPipeClientPlugin*)handle)->flushMessages();
  647. }
  648. bool carla_pipe_client_flush_and_unlock(CarlaPipeClientHandle handle)
  649. {
  650. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  651. CarlaPipeClientPlugin* const pipe((CarlaPipeClientPlugin*)handle);
  652. const bool ret(pipe->flushMessages());
  653. pipe->unlockPipe();
  654. return ret;
  655. }
  656. void carla_pipe_client_destroy(CarlaPipeClientHandle handle)
  657. {
  658. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  659. carla_debug("carla_pipe_client_destroy(%p)", handle);
  660. CarlaPipeClientPlugin* const pipe((CarlaPipeClientPlugin*)handle);
  661. pipe->closePipeClient();
  662. delete pipe;
  663. }
  664. // -------------------------------------------------------------------------------------------------------------------
  665. const char* carla_get_library_filename()
  666. {
  667. carla_debug("carla_get_library_filename()");
  668. static CarlaString ret;
  669. if (ret.isEmpty())
  670. {
  671. using juce::File;
  672. ret = File(File::getSpecialLocation(File::currentExecutableFile)).getFullPathName().toRawUTF8();
  673. }
  674. return ret;
  675. }
  676. const char* carla_get_library_folder()
  677. {
  678. carla_debug("carla_get_library_folder()");
  679. static CarlaString ret;
  680. if (ret.isEmpty())
  681. {
  682. using juce::File;
  683. ret = File(File::getSpecialLocation(File::currentExecutableFile).getParentDirectory()).getFullPathName().toRawUTF8();
  684. }
  685. return ret;
  686. }
  687. // -------------------------------------------------------------------------------------------------------------------
  688. void carla_x11_reparent_window(uintptr_t winId1, uintptr_t winId2)
  689. {
  690. carla_debug("carla_x11_reparent_window()");
  691. #ifdef HAVE_X11
  692. if (::Display* const disp = XOpenDisplay(nullptr))
  693. {
  694. XReparentWindow(disp, winId1, winId2, 0, 0);
  695. XMapWindow(disp, winId1);
  696. XCloseDisplay(disp);
  697. }
  698. #endif
  699. }
  700. void carla_x11_move_window(uintptr_t winId, int x, int y)
  701. {
  702. #ifdef HAVE_X11
  703. if (::Display* const disp = XOpenDisplay(nullptr))
  704. {
  705. XMoveWindow(disp, winId, x, y);
  706. XCloseDisplay(disp);
  707. }
  708. #endif
  709. }
  710. int* carla_x11_get_window_pos(uintptr_t winId)
  711. {
  712. carla_debug("carla_x11_get_window_pos()");
  713. static int pos[2];
  714. #ifdef HAVE_X11
  715. if (::Display* const disp = XOpenDisplay(nullptr))
  716. {
  717. int x, y;
  718. Window child;
  719. XWindowAttributes xwa;
  720. XTranslateCoordinates(disp, winId, XRootWindow(disp, 0), 0, 0, &x, &y, &child);
  721. XGetWindowAttributes(disp, winId, &xwa);
  722. XCloseDisplay(disp);
  723. pos[0] = x - xwa.x;
  724. pos[1] = y - xwa.y;
  725. }
  726. else
  727. #endif
  728. {
  729. pos[0] = 0;
  730. pos[1] = 0;
  731. }
  732. return pos;
  733. }
  734. // -------------------------------------------------------------------------------------------------------------------
  735. #include "CarlaPipeUtils.cpp"
  736. // -------------------------------------------------------------------------------------------------------------------
  737. #endif // CARLA_UTILS_CACHED_PLUGINS_ONLY