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.

CarlaUtils.cpp 29KB

8 years ago
8 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  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);
  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_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. void carla_x11_reparent_window(uintptr_t winId1, uintptr_t winId2)
  681. {
  682. carla_debug("carla_x11_reparent_window()");
  683. #ifdef HAVE_X11
  684. if (::Display* const disp = XOpenDisplay(nullptr))
  685. {
  686. XReparentWindow(disp, winId1, winId2, 0, 0);
  687. XMapWindow(disp, winId1);
  688. XCloseDisplay(disp);
  689. }
  690. #endif
  691. }
  692. void carla_x11_move_window(uintptr_t winId, int x, int y)
  693. {
  694. #ifdef HAVE_X11
  695. if (::Display* const disp = XOpenDisplay(nullptr))
  696. {
  697. XMoveWindow(disp, winId, x, y);
  698. XCloseDisplay(disp);
  699. }
  700. #endif
  701. }
  702. int* carla_x11_get_window_pos(uintptr_t winId)
  703. {
  704. carla_debug("carla_x11_get_window_pos()");
  705. static int pos[2];
  706. #ifdef HAVE_X11
  707. if (::Display* const disp = XOpenDisplay(nullptr))
  708. {
  709. int x, y;
  710. Window child;
  711. XWindowAttributes xwa;
  712. XTranslateCoordinates(disp, winId, XRootWindow(disp, 0), 0, 0, &x, &y, &child);
  713. XGetWindowAttributes(disp, winId, &xwa);
  714. XCloseDisplay(disp);
  715. pos[0] = x - xwa.x;
  716. pos[1] = y - xwa.y;
  717. }
  718. else
  719. #endif
  720. {
  721. pos[0] = 0;
  722. pos[1] = 0;
  723. }
  724. return pos;
  725. }
  726. // -------------------------------------------------------------------------------------------------------------------
  727. #include "CarlaPipeUtils.cpp"
  728. // -------------------------------------------------------------------------------------------------------------------
  729. #endif // CARLA_UTILS_CACHED_PLUGINS_ONLY