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.

831 lines
28KB

  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. #endif
  27. #ifdef CARLA_OS_MAC
  28. # include "juce_audio_processors/juce_audio_processors.h"
  29. #endif
  30. #include "../native-plugins/_data.cpp"
  31. namespace CB = CarlaBackend;
  32. static const char* const gNullCharPtr = "";
  33. #ifdef CARLA_OS_MAC
  34. static juce::StringArray gCachedAuPluginResults;
  35. #endif
  36. // -------------------------------------------------------------------------------------------------------------------
  37. _CarlaCachedPluginInfo::_CarlaCachedPluginInfo() noexcept
  38. : category(CB::PLUGIN_CATEGORY_NONE),
  39. hints(0x0),
  40. audioIns(0),
  41. audioOuts(0),
  42. midiIns(0),
  43. midiOuts(0),
  44. parameterIns(0),
  45. parameterOuts(0),
  46. name(gNullCharPtr),
  47. label(gNullCharPtr),
  48. maker(gNullCharPtr),
  49. copyright(gNullCharPtr) {}
  50. // -------------------------------------------------------------------------------------------------------------------
  51. uint carla_get_cached_plugin_count(CB::PluginType ptype, const char* pluginPath)
  52. {
  53. CARLA_SAFE_ASSERT_RETURN(ptype == CB::PLUGIN_INTERNAL || ptype == CB::PLUGIN_LV2 || ptype == CB::PLUGIN_AU, 0);
  54. carla_debug("carla_get_cached_plugin_count(%i:%s)", ptype, CB::PluginType2Str(ptype));
  55. switch (ptype)
  56. {
  57. case CB::PLUGIN_INTERNAL: {
  58. uint32_t count = 0;
  59. carla_get_native_plugins_data(&count);
  60. return count;
  61. }
  62. case CB::PLUGIN_LV2: {
  63. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  64. lv2World.initIfNeeded(pluginPath);
  65. return lv2World.getPluginCount();
  66. }
  67. case CB::PLUGIN_AU: {
  68. #ifdef CARLA_OS_MAC
  69. static bool initiated = false;
  70. if (! initiated)
  71. {
  72. using namespace juce;
  73. initiated = true;
  74. AudioUnitPluginFormat auFormat;
  75. gCachedAuPluginResults = auFormat.searchPathsForPlugins(juce::FileSearchPath(), false);
  76. }
  77. return static_cast<uint>(gCachedAuPluginResults.size());
  78. #else
  79. return 0;
  80. #endif
  81. }
  82. default:
  83. return 0;
  84. }
  85. }
  86. const CarlaCachedPluginInfo* carla_get_cached_plugin_info(CB::PluginType ptype, uint index)
  87. {
  88. carla_debug("carla_get_cached_plugin_info(%i:%s, %i)", ptype, CB::PluginType2Str(ptype), index);
  89. static CarlaCachedPluginInfo info;
  90. switch (ptype)
  91. {
  92. case CB::PLUGIN_INTERNAL: {
  93. uint32_t count = 0;
  94. const NativePluginDescriptor* const descs(carla_get_native_plugins_data(&count));
  95. CARLA_SAFE_ASSERT_BREAK(index < count);
  96. CARLA_SAFE_ASSERT_BREAK(descs != nullptr);
  97. const NativePluginDescriptor& desc(descs[index]);
  98. info.category = static_cast<CB::PluginCategory>(desc.category);
  99. info.hints = 0x0;
  100. if (desc.hints & NATIVE_PLUGIN_IS_RTSAFE)
  101. info.hints |= CB::PLUGIN_IS_RTSAFE;
  102. if (desc.hints & NATIVE_PLUGIN_IS_SYNTH)
  103. info.hints |= CB::PLUGIN_IS_SYNTH;
  104. if (desc.hints & NATIVE_PLUGIN_HAS_UI)
  105. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  106. if (desc.hints & NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS)
  107. info.hints |= CB::PLUGIN_NEEDS_FIXED_BUFFERS;
  108. if (desc.hints & NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD)
  109. info.hints |= CB::PLUGIN_NEEDS_UI_MAIN_THREAD;
  110. if (desc.hints & NATIVE_PLUGIN_USES_MULTI_PROGS)
  111. info.hints |= CB::PLUGIN_USES_MULTI_PROGS;
  112. info.audioIns = desc.audioIns;
  113. info.audioOuts = desc.audioOuts;
  114. info.midiIns = desc.midiIns;
  115. info.midiOuts = desc.midiOuts;
  116. info.parameterIns = desc.paramIns;
  117. info.parameterOuts = desc.paramOuts;
  118. info.name = desc.name;
  119. info.label = desc.label;
  120. info.maker = desc.maker;
  121. info.copyright = desc.copyright;
  122. return &info;
  123. }
  124. case CB::PLUGIN_LV2: {
  125. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  126. const LilvPlugin* const cPlugin(lv2World.getPluginFromIndex(index));
  127. CARLA_SAFE_ASSERT_BREAK(cPlugin != nullptr);
  128. Lilv::Plugin lilvPlugin(cPlugin);
  129. CARLA_SAFE_ASSERT_BREAK(lilvPlugin.get_uri().is_uri());
  130. carla_stdout("Filling info for LV2 with URI '%s'", lilvPlugin.get_uri().as_uri());
  131. // features
  132. info.hints = 0x0;
  133. if (lilvPlugin.get_uis().size() > 0 || lilvPlugin.get_modgui_resources_directory().as_uri() != nullptr)
  134. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  135. {
  136. Lilv::Nodes lilvFeatureNodes(lilvPlugin.get_supported_features());
  137. LILV_FOREACH(nodes, it, lilvFeatureNodes)
  138. {
  139. Lilv::Node lilvFeatureNode(lilvFeatureNodes.get(it));
  140. const char* const featureURI(lilvFeatureNode.as_uri());
  141. CARLA_SAFE_ASSERT_CONTINUE(featureURI != nullptr);
  142. if (std::strcmp(featureURI, LV2_CORE__hardRTCapable) == 0)
  143. info.hints |= CB::PLUGIN_IS_RTSAFE;
  144. }
  145. lilv_nodes_free(const_cast<LilvNodes*>(lilvFeatureNodes.me));
  146. }
  147. // category
  148. info.category = CB::PLUGIN_CATEGORY_NONE;
  149. {
  150. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  151. if (typeNodes.size() > 0)
  152. {
  153. if (typeNodes.contains(lv2World.class_allpass))
  154. info.category = CB::PLUGIN_CATEGORY_FILTER;
  155. if (typeNodes.contains(lv2World.class_amplifier))
  156. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  157. if (typeNodes.contains(lv2World.class_analyzer))
  158. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  159. if (typeNodes.contains(lv2World.class_bandpass))
  160. info.category = CB::PLUGIN_CATEGORY_FILTER;
  161. if (typeNodes.contains(lv2World.class_chorus))
  162. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  163. if (typeNodes.contains(lv2World.class_comb))
  164. info.category = CB::PLUGIN_CATEGORY_FILTER;
  165. if (typeNodes.contains(lv2World.class_compressor))
  166. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  167. if (typeNodes.contains(lv2World.class_constant))
  168. info.category = CB::PLUGIN_CATEGORY_OTHER;
  169. if (typeNodes.contains(lv2World.class_converter))
  170. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  171. if (typeNodes.contains(lv2World.class_delay))
  172. info.category = CB::PLUGIN_CATEGORY_DELAY;
  173. if (typeNodes.contains(lv2World.class_distortion))
  174. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  175. if (typeNodes.contains(lv2World.class_dynamics))
  176. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  177. if (typeNodes.contains(lv2World.class_eq))
  178. info.category = CB::PLUGIN_CATEGORY_EQ;
  179. if (typeNodes.contains(lv2World.class_envelope))
  180. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  181. if (typeNodes.contains(lv2World.class_expander))
  182. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  183. if (typeNodes.contains(lv2World.class_filter))
  184. info.category = CB::PLUGIN_CATEGORY_FILTER;
  185. if (typeNodes.contains(lv2World.class_flanger))
  186. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  187. if (typeNodes.contains(lv2World.class_function))
  188. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  189. if (typeNodes.contains(lv2World.class_gate))
  190. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  191. if (typeNodes.contains(lv2World.class_generator))
  192. info.category = CB::PLUGIN_CATEGORY_OTHER;
  193. if (typeNodes.contains(lv2World.class_highpass))
  194. info.category = CB::PLUGIN_CATEGORY_FILTER;
  195. if (typeNodes.contains(lv2World.class_limiter))
  196. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  197. if (typeNodes.contains(lv2World.class_lowpass))
  198. info.category = CB::PLUGIN_CATEGORY_FILTER;
  199. if (typeNodes.contains(lv2World.class_mixer))
  200. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  201. if (typeNodes.contains(lv2World.class_modulator))
  202. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  203. if (typeNodes.contains(lv2World.class_multiEQ))
  204. info.category = CB::PLUGIN_CATEGORY_EQ;
  205. if (typeNodes.contains(lv2World.class_oscillator))
  206. info.category = CB::PLUGIN_CATEGORY_OTHER;
  207. if (typeNodes.contains(lv2World.class_paraEQ))
  208. info.category = CB::PLUGIN_CATEGORY_EQ;
  209. if (typeNodes.contains(lv2World.class_phaser))
  210. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  211. if (typeNodes.contains(lv2World.class_pitch))
  212. info.category = CB::PLUGIN_CATEGORY_OTHER;
  213. if (typeNodes.contains(lv2World.class_reverb))
  214. info.category = CB::PLUGIN_CATEGORY_DELAY;
  215. if (typeNodes.contains(lv2World.class_simulator))
  216. info.category = CB::PLUGIN_CATEGORY_OTHER;
  217. if (typeNodes.contains(lv2World.class_spatial))
  218. info.category = CB::PLUGIN_CATEGORY_OTHER;
  219. if (typeNodes.contains(lv2World.class_spectral))
  220. info.category = CB::PLUGIN_CATEGORY_OTHER;
  221. if (typeNodes.contains(lv2World.class_utility))
  222. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  223. if (typeNodes.contains(lv2World.class_waveshaper))
  224. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  225. if (typeNodes.contains(lv2World.class_instrument))
  226. {
  227. info.category = CB::PLUGIN_CATEGORY_SYNTH;
  228. info.hints |= CB::PLUGIN_IS_SYNTH;
  229. }
  230. }
  231. lilv_nodes_free(const_cast<LilvNodes*>(typeNodes.me));
  232. }
  233. // number data
  234. info.audioIns = 0;
  235. info.audioOuts = 0;
  236. info.midiIns = 0;
  237. info.midiOuts = 0;
  238. info.parameterIns = 0;
  239. info.parameterOuts = 0;
  240. for (uint i=0, count=lilvPlugin.get_num_ports(); i<count; ++i)
  241. {
  242. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(i));
  243. bool isInput;
  244. /**/ if (lilvPort.is_a(lv2World.port_input))
  245. isInput = true;
  246. else if (lilvPort.is_a(lv2World.port_output))
  247. isInput = false;
  248. else
  249. continue;
  250. /**/ if (lilvPort.is_a(lv2World.port_control))
  251. {
  252. // skip some control ports
  253. if (lilvPort.has_property(lv2World.reportsLatency))
  254. continue;
  255. if (LilvNode* const designationNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.designation.me))
  256. {
  257. bool skip = false;
  258. if (const char* const designation = lilv_node_as_string(designationNode))
  259. {
  260. /**/ if (std::strcmp(designation, LV2_CORE__control) == 0)
  261. skip = true;
  262. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  263. skip = true;
  264. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  265. skip = true;
  266. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  267. skip = true;
  268. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  269. skip = true;
  270. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  271. skip = true;
  272. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  273. skip = true;
  274. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  275. skip = true;
  276. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  277. skip = true;
  278. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  279. skip = true;
  280. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  281. skip = true;
  282. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  283. skip = true;
  284. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  285. skip = true;
  286. else if (std::strcmp(designation, LV2_KXSTUDIO_PROPERTIES__TimePositionTicksPerBeat) == 0)
  287. skip = true;
  288. }
  289. lilv_node_free(designationNode);
  290. if (skip)
  291. continue;
  292. }
  293. if (isInput)
  294. ++(info.parameterIns);
  295. else
  296. ++(info.parameterOuts);
  297. }
  298. else if (lilvPort.is_a(lv2World.port_audio))
  299. {
  300. if (isInput)
  301. ++(info.audioIns);
  302. else
  303. ++(info.audioOuts);
  304. }
  305. else if (lilvPort.is_a(lv2World.port_cv))
  306. {
  307. }
  308. else if (lilvPort.is_a(lv2World.port_atom))
  309. {
  310. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  311. for (LilvIter *it = lilv_nodes_begin(supportNodes.me); ! lilv_nodes_is_end(supportNodes.me, it); it = lilv_nodes_next(supportNodes.me, it))
  312. {
  313. const Lilv::Node node(lilv_nodes_get(supportNodes.me, it));
  314. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  315. if (node.equals(lv2World.midi_event))
  316. {
  317. if (isInput)
  318. ++(info.midiIns);
  319. else
  320. ++(info.midiOuts);
  321. }
  322. }
  323. lilv_nodes_free(const_cast<LilvNodes*>(supportNodes.me));
  324. }
  325. else if (lilvPort.is_a(lv2World.port_event))
  326. {
  327. if (lilvPort.supports_event(lv2World.midi_event))
  328. {
  329. if (isInput)
  330. ++(info.midiIns);
  331. else
  332. ++(info.midiOuts);
  333. }
  334. }
  335. else if (lilvPort.is_a(lv2World.port_midi))
  336. {
  337. if (isInput)
  338. ++(info.midiIns);
  339. else
  340. ++(info.midiOuts);
  341. }
  342. }
  343. // text data
  344. static CarlaString suri, sname, smaker, slicense;
  345. suri.clear(); sname.clear(); smaker.clear(); slicense.clear();
  346. suri = lilvPlugin.get_uri().as_uri();
  347. if (LilvNode* const nameNode = lilv_plugin_get_name(lilvPlugin.me))
  348. {
  349. if (const char* const name = lilv_node_as_string(nameNode))
  350. sname = name;
  351. lilv_node_free(nameNode);
  352. }
  353. if (const char* const author = lilvPlugin.get_author_name().as_string())
  354. smaker = author;
  355. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  356. if (licenseNodes.size() > 0)
  357. {
  358. if (const char* const license = licenseNodes.get_first().as_string())
  359. slicense = license;
  360. }
  361. lilv_nodes_free(const_cast<LilvNodes*>(licenseNodes.me));
  362. info.name = sname;
  363. info.label = suri;
  364. info.maker = smaker;
  365. info.copyright = slicense;
  366. return &info;
  367. }
  368. case CB::PLUGIN_AU: {
  369. #ifdef CARLA_OS_MAC
  370. const int indexi(static_cast<int>(index));
  371. CARLA_SAFE_ASSERT_BREAK(indexi < gCachedAuPluginResults.size());
  372. using namespace juce;
  373. String pluginId(gCachedAuPluginResults[indexi]);
  374. OwnedArray<PluginDescription> results;
  375. AudioUnitPluginFormat auFormat;
  376. auFormat.findAllTypesForFile(results, pluginId);
  377. CARLA_SAFE_ASSERT_BREAK(results.size() > 0);
  378. CARLA_SAFE_ASSERT(results.size() == 1);
  379. PluginDescription* const desc(results[0]);
  380. CARLA_SAFE_ASSERT_BREAK(desc != nullptr);
  381. info.category = CB::getPluginCategoryFromName(desc->category.toRawUTF8());
  382. info.hints = 0x0;
  383. if (desc->isInstrument)
  384. info.hints |= CB::PLUGIN_IS_SYNTH;
  385. if (true)
  386. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  387. info.audioIns = static_cast<uint32_t>(desc->numInputChannels);
  388. info.audioOuts = static_cast<uint32_t>(desc->numOutputChannels);
  389. info.midiIns = desc->isInstrument ? 1 : 0;
  390. info.midiOuts = 0;
  391. info.parameterIns = 0;
  392. info.parameterOuts = 0;
  393. static CarlaString sname, slabel, smaker;
  394. sname = desc->name.toRawUTF8();
  395. slabel = desc->fileOrIdentifier.toRawUTF8();
  396. smaker = desc->manufacturerName.toRawUTF8();
  397. info.name = sname;
  398. info.label = slabel;
  399. info.maker = smaker;
  400. info.copyright = gNullCharPtr;
  401. return &info;
  402. #else
  403. break;
  404. #endif
  405. }
  406. default:
  407. break;
  408. }
  409. info.category = CB::PLUGIN_CATEGORY_NONE;
  410. info.hints = 0x0;
  411. info.audioIns = 0;
  412. info.audioOuts = 0;
  413. info.midiIns = 0;
  414. info.midiOuts = 0;
  415. info.parameterIns = 0;
  416. info.parameterOuts = 0;
  417. info.name = gNullCharPtr;
  418. info.label = gNullCharPtr;
  419. info.maker = gNullCharPtr;
  420. info.copyright = gNullCharPtr;
  421. return &info;
  422. }
  423. #ifndef CARLA_UTILS_CACHED_PLUGINS_ONLY
  424. // -------------------------------------------------------------------------------------------------------------------
  425. const char* carla_get_complete_license_text()
  426. {
  427. carla_debug("carla_get_complete_license_text()");
  428. static CarlaString retText;
  429. if (retText.isEmpty())
  430. {
  431. retText =
  432. "<p>This current Carla build is using the following features and 3rd-party code:</p>"
  433. "<ul>"
  434. #if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN) || ! defined(VESTIGE_HEADER)
  435. # define LS_NOTE_NO "2"
  436. #else
  437. # define LS_NOTE_NO "1"
  438. #endif
  439. // Plugin formats
  440. "<li>LADSPA plugin support</li>"
  441. "<li>DSSI plugin support</li>"
  442. "<li>LV2 plugin support</li>"
  443. #ifdef VESTIGE_HEADER
  444. "<li>VST2 plugin support using VeSTige header by Javier Serrano Polo</li>"
  445. #else
  446. "<li>VST2 plugin support using official VST SDK 2.4 [1]</li>"
  447. #endif
  448. #if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
  449. "<li>VST3 plugin support using official VST SDK 3.6 [1]</li>"
  450. #endif
  451. #ifdef CARLA_OS_MAC
  452. "<li>AU plugin support</li>"
  453. #endif
  454. // Sample kit libraries
  455. #ifdef HAVE_FLUIDSYNTH
  456. "<li>FluidSynth library for SF2 support</li>"
  457. #endif
  458. #ifdef HAVE_LINUXSAMPLER
  459. "<li>LinuxSampler library for GIG and SFZ support [" LS_NOTE_NO "]</li>"
  460. #endif
  461. // misc libs
  462. "<li>base64 utilities based on code by Ren\u00E9 Nyffenegger</li>"
  463. #ifdef CARLA_OS_MAC
  464. "<li>sem_timedwait for Mac OS by Keith Shortridge</li>"
  465. #endif
  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 = "3.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_set_process_name(const char* name)
  554. {
  555. carla_debug("carla_set_process_name(\"%s\")", name);
  556. CarlaThread::setCurrentThreadName(name);
  557. juce::Thread::setCurrentThreadName(name);
  558. }
  559. // -------------------------------------------------------------------------------------------------------------------
  560. class CarlaPipeClientPlugin : public CarlaPipeClient
  561. {
  562. public:
  563. CarlaPipeClientPlugin(const CarlaPipeCallbackFunc callbackFunc, void* const callbackPtr) noexcept
  564. : CarlaPipeClient(),
  565. fCallbackFunc(callbackFunc),
  566. fCallbackPtr(callbackPtr)
  567. {
  568. CARLA_SAFE_ASSERT(fCallbackFunc != nullptr);
  569. }
  570. const char* readlineblock(const uint timeout) noexcept
  571. {
  572. return CarlaPipeClient::_readlineblock(timeout);
  573. }
  574. bool msgReceived(const char* const msg) noexcept
  575. {
  576. if (fCallbackFunc != nullptr)
  577. {
  578. try {
  579. fCallbackFunc(fCallbackPtr, msg);
  580. } CARLA_SAFE_EXCEPTION("msgReceived");
  581. }
  582. return true;
  583. }
  584. private:
  585. const CarlaPipeCallbackFunc fCallbackFunc;
  586. void* const fCallbackPtr;
  587. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPipeClientPlugin)
  588. };
  589. CarlaPipeClientHandle carla_pipe_client_new(const char* argv[], CarlaPipeCallbackFunc callbackFunc, void* callbackPtr)
  590. {
  591. carla_debug("carla_pipe_client_new(%p, %p, %p)", argv, callbackFunc, callbackPtr);
  592. CarlaPipeClientPlugin* const pipe(new CarlaPipeClientPlugin(callbackFunc, callbackPtr));
  593. if (! pipe->initPipeClient(argv))
  594. {
  595. delete pipe;
  596. return nullptr;
  597. }
  598. return pipe;
  599. }
  600. void carla_pipe_client_idle(CarlaPipeClientHandle handle)
  601. {
  602. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  603. ((CarlaPipeClientPlugin*)handle)->idlePipe();
  604. }
  605. bool carla_pipe_client_is_running(CarlaPipeClientHandle handle)
  606. {
  607. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  608. return ((CarlaPipeClientPlugin*)handle)->isPipeRunning();
  609. }
  610. void carla_pipe_client_lock(CarlaPipeClientHandle handle)
  611. {
  612. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  613. return ((CarlaPipeClientPlugin*)handle)->lockPipe();
  614. }
  615. void carla_pipe_client_unlock(CarlaPipeClientHandle handle)
  616. {
  617. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  618. return ((CarlaPipeClientPlugin*)handle)->unlockPipe();
  619. }
  620. const char* carla_pipe_client_readlineblock(CarlaPipeClientHandle handle, uint timeout)
  621. {
  622. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, nullptr);
  623. return ((CarlaPipeClientPlugin*)handle)->readlineblock(timeout);
  624. }
  625. bool carla_pipe_client_write_msg(CarlaPipeClientHandle handle, const char* msg)
  626. {
  627. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  628. return ((CarlaPipeClientPlugin*)handle)->writeMessage(msg);
  629. }
  630. bool carla_pipe_client_write_and_fix_msg(CarlaPipeClientHandle handle, const char* msg)
  631. {
  632. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  633. return ((CarlaPipeClientPlugin*)handle)->writeAndFixMessage(msg);
  634. }
  635. bool carla_pipe_client_flush(CarlaPipeClientHandle handle)
  636. {
  637. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  638. return ((CarlaPipeClientPlugin*)handle)->flushMessages();
  639. }
  640. bool carla_pipe_client_flush_and_unlock(CarlaPipeClientHandle handle)
  641. {
  642. CARLA_SAFE_ASSERT_RETURN(handle != nullptr, false);
  643. CarlaPipeClientPlugin* const pipe((CarlaPipeClientPlugin*)handle);
  644. const bool ret(pipe->flushMessages());
  645. pipe->unlockPipe();
  646. return ret;
  647. }
  648. void carla_pipe_client_destroy(CarlaPipeClientHandle handle)
  649. {
  650. CARLA_SAFE_ASSERT_RETURN(handle != nullptr,);
  651. carla_debug("carla_pipe_client_destroy(%p)", handle);
  652. CarlaPipeClientPlugin* const pipe((CarlaPipeClientPlugin*)handle);
  653. pipe->closePipeClient();
  654. delete pipe;
  655. }
  656. // -------------------------------------------------------------------------------------------------------------------
  657. const char* carla_get_library_filename()
  658. {
  659. carla_debug("carla_get_library_filename()");
  660. static CarlaString ret;
  661. if (ret.isEmpty())
  662. {
  663. using juce::File;
  664. ret = File(File::getSpecialLocation(File::currentExecutableFile)).getFullPathName().toRawUTF8();
  665. }
  666. return ret;
  667. }
  668. const char* carla_get_library_folder()
  669. {
  670. carla_debug("carla_get_library_folder()");
  671. static CarlaString ret;
  672. if (ret.isEmpty())
  673. {
  674. using juce::File;
  675. ret = File(File::getSpecialLocation(File::currentExecutableFile).getParentDirectory()).getFullPathName().toRawUTF8();
  676. }
  677. return ret;
  678. }
  679. // -------------------------------------------------------------------------------------------------------------------
  680. #include "CarlaPipeUtils.cpp"
  681. // -------------------------------------------------------------------------------------------------------------------
  682. #endif // CARLA_UTILS_CACHED_PLUGINS_ONLY