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.

CachedPlugins.cpp 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2020 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 "CarlaString.hpp"
  20. #include "CarlaBackendUtils.hpp"
  21. #include "CarlaScopeUtils.hpp"
  22. #include "CarlaLv2Utils.hpp"
  23. #include "CarlaJsfxUtils.hpp"
  24. #if defined(USING_JUCE) && defined(CARLA_OS_MAC)
  25. # include "AppConfig.h"
  26. # include "juce_audio_processors/juce_audio_processors.h"
  27. #endif
  28. #include "water/containers/Array.h"
  29. #include "water/files/File.h"
  30. namespace CB = CarlaBackend;
  31. // -------------------------------------------------------------------------------------------------------------------
  32. static const char* const gCachedPluginsNullCharPtr = "";
  33. static bool isCachedPluginType(const CB::PluginType ptype)
  34. {
  35. switch (ptype)
  36. {
  37. case CB::PLUGIN_INTERNAL:
  38. case CB::PLUGIN_LV2:
  39. case CB::PLUGIN_AU:
  40. case CB::PLUGIN_SFZ:
  41. case CB::PLUGIN_JSFX:
  42. return true;
  43. default:
  44. return false;
  45. }
  46. }
  47. // -------------------------------------------------------------------------------------------------------------------
  48. _CarlaCachedPluginInfo::_CarlaCachedPluginInfo() noexcept
  49. : valid(false),
  50. category(CB::PLUGIN_CATEGORY_NONE),
  51. hints(0x0),
  52. audioIns(0),
  53. audioOuts(0),
  54. cvIns(0),
  55. cvOuts(0),
  56. midiIns(0),
  57. midiOuts(0),
  58. parameterIns(0),
  59. parameterOuts(0),
  60. name(gCachedPluginsNullCharPtr),
  61. label(gCachedPluginsNullCharPtr),
  62. maker(gCachedPluginsNullCharPtr),
  63. copyright(gCachedPluginsNullCharPtr) {}
  64. // -------------------------------------------------------------------------------------------------------------------
  65. static water::Array<water::File> gSFZs;
  66. static void findSFZs(const char* const sfzPaths)
  67. {
  68. gSFZs.clearQuick();
  69. CARLA_SAFE_ASSERT_RETURN(sfzPaths != nullptr,);
  70. if (sfzPaths[0] == '\0')
  71. return;
  72. const water::StringArray splitPaths(water::StringArray::fromTokens(sfzPaths, CARLA_OS_SPLIT_STR, ""));
  73. for (water::String *it = splitPaths.begin(), *end = splitPaths.end(); it != end; ++it)
  74. {
  75. water::Array<water::File> results;
  76. if (water::File(*it).findChildFiles(results, water::File::findFiles|water::File::ignoreHiddenFiles, true, "*.sfz") > 0)
  77. gSFZs.addArray(results);
  78. }
  79. }
  80. // -------------------------------------------------------------------------------------------------------------------
  81. static water::Array<water::File> gJSFXs;
  82. static void findJSFXs(const char* const jsfxPaths)
  83. {
  84. gJSFXs.clearQuick();
  85. CARLA_SAFE_ASSERT_RETURN(jsfxPaths != nullptr,);
  86. if (jsfxPaths[0] == '\0')
  87. return;
  88. const water::StringArray splitPaths(water::StringArray::fromTokens(jsfxPaths, CARLA_OS_SPLIT_STR, ""));
  89. for (water::String *it = splitPaths.begin(), *end = splitPaths.end(); it != end; ++it)
  90. {
  91. water::Array<water::File> results;
  92. if (water::File(*it).findChildFiles(results, water::File::findFiles|water::File::ignoreHiddenFiles, true, "*") > 0)
  93. {
  94. for (const water::File& file : results)
  95. {
  96. if (!file.hasFileExtension("jsfx-inc"))
  97. gJSFXs.add(file);
  98. }
  99. }
  100. }
  101. }
  102. // -------------------------------------------------------------------------------------------------------------------
  103. static const CarlaCachedPluginInfo* get_cached_plugin_internal(const NativePluginDescriptor& desc)
  104. {
  105. static CarlaCachedPluginInfo info;
  106. info.category = static_cast<CB::PluginCategory>(desc.category);
  107. info.hints = 0x0;
  108. if (desc.hints & NATIVE_PLUGIN_IS_RTSAFE)
  109. info.hints |= CB::PLUGIN_IS_RTSAFE;
  110. if (desc.hints & NATIVE_PLUGIN_IS_SYNTH)
  111. info.hints |= CB::PLUGIN_IS_SYNTH;
  112. if (desc.hints & NATIVE_PLUGIN_HAS_UI)
  113. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  114. if (desc.hints & NATIVE_PLUGIN_HAS_INLINE_DISPLAY)
  115. info.hints |= CB::PLUGIN_HAS_INLINE_DISPLAY;
  116. if (desc.hints & NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS)
  117. info.hints |= CB::PLUGIN_NEEDS_FIXED_BUFFERS;
  118. if (desc.hints & NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD)
  119. info.hints |= CB::PLUGIN_NEEDS_UI_MAIN_THREAD;
  120. if (desc.hints & NATIVE_PLUGIN_USES_MULTI_PROGS)
  121. info.hints |= CB::PLUGIN_USES_MULTI_PROGS;
  122. info.valid = true;
  123. info.audioIns = desc.audioIns;
  124. info.audioOuts = desc.audioOuts;
  125. info.cvIns = desc.cvIns;
  126. info.cvOuts = desc.cvOuts;
  127. info.midiIns = desc.midiIns;
  128. info.midiOuts = desc.midiOuts;
  129. info.parameterIns = desc.paramIns;
  130. info.parameterOuts = desc.paramOuts;
  131. info.name = desc.name;
  132. info.label = desc.label;
  133. info.maker = desc.maker;
  134. info.copyright = desc.copyright;
  135. return &info;
  136. }
  137. // -------------------------------------------------------------------------------------------------------------------
  138. static const CarlaCachedPluginInfo* get_cached_plugin_lv2(Lv2WorldClass& lv2World, Lilv::Plugin& lilvPlugin)
  139. {
  140. static CarlaCachedPluginInfo info;
  141. info.valid = false;
  142. bool supported = true;
  143. // ----------------------------------------------------------------------------------------------------------------
  144. // text data
  145. {
  146. static CarlaString suri, sname, smaker, slicense;
  147. suri.clear(); sname.clear(); smaker.clear(); slicense.clear();
  148. suri = lilvPlugin.get_uri().as_uri();
  149. if (char* const bundle = lilv_file_uri_parse(lilvPlugin.get_bundle_uri().as_uri(), nullptr))
  150. {
  151. water::File fbundle(bundle);
  152. lilv_free(bundle);
  153. suri = (fbundle.getFileName() + CARLA_OS_SEP).toRawUTF8() + suri;
  154. }
  155. else
  156. {
  157. suri = CARLA_OS_SEP_STR + suri;
  158. }
  159. #if 0 // def HAVE_FLUIDSYNTH
  160. // If we have fluidsynth support built-in, loading these plugins will lead to issues
  161. if (suri == "urn:ardour:a-fluidsynth")
  162. return &info;
  163. if (suri == "http://calf.sourceforge.net/plugins/Fluidsynth")
  164. return &info;
  165. #endif
  166. if (LilvNode* const nameNode = lilv_plugin_get_name(lilvPlugin.me))
  167. {
  168. if (const char* const name = lilv_node_as_string(nameNode))
  169. sname = name;
  170. lilv_node_free(nameNode);
  171. }
  172. if (LilvNode* const authorNode = lilv_plugin_get_author_name(lilvPlugin.me))
  173. {
  174. if (const char* const author = lilv_node_as_string(authorNode))
  175. smaker = author;
  176. lilv_node_free(authorNode);
  177. }
  178. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  179. if (licenseNodes.size() > 0)
  180. {
  181. if (LilvNode* const licenseNode = lilv_nodes_get_first(licenseNodes.me))
  182. {
  183. if (const char* const license = lilv_node_as_string(licenseNode))
  184. slicense = license;
  185. // lilv_node_free(licenseNode);
  186. }
  187. }
  188. lilv_nodes_free(const_cast<LilvNodes*>(licenseNodes.me));
  189. info.name = sname.buffer();
  190. info.label = suri.buffer();
  191. info.maker = smaker.buffer();
  192. info.copyright = slicense.buffer();
  193. }
  194. // ----------------------------------------------------------------------------------------------------------------
  195. // features
  196. info.hints = 0x0;
  197. {
  198. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  199. if (lilvUIs.size() > 0)
  200. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  201. #ifdef CARLA_OS_LINUX
  202. else if (lilvPlugin.get_modgui_resources_directory().as_uri() != nullptr)
  203. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  204. #endif
  205. lilv_nodes_free(const_cast<LilvNodes*>(lilvUIs.me));
  206. }
  207. {
  208. Lilv::Nodes lilvRequiredFeatureNodes(lilvPlugin.get_required_features());
  209. LILV_FOREACH(nodes, it, lilvRequiredFeatureNodes)
  210. {
  211. Lilv::Node lilvFeatureNode(lilvRequiredFeatureNodes.get(it));
  212. const char* const featureURI(lilvFeatureNode.as_uri());
  213. CARLA_SAFE_ASSERT_CONTINUE(featureURI != nullptr);
  214. if (! is_lv2_feature_supported(featureURI))
  215. {
  216. if (std::strcmp(featureURI, LV2_DATA_ACCESS_URI) == 0
  217. || std::strcmp(featureURI, LV2_INSTANCE_ACCESS_URI) == 0)
  218. {
  219. // we give a warning about this below
  220. continue;
  221. }
  222. supported = false;
  223. carla_stderr("LV2 plugin '%s' requires unsupported feature '%s'", info.label, featureURI);
  224. }
  225. }
  226. lilv_nodes_free(const_cast<LilvNodes*>(lilvRequiredFeatureNodes.me));
  227. }
  228. {
  229. Lilv::Nodes lilvSupportedFeatureNodes(lilvPlugin.get_supported_features());
  230. LILV_FOREACH(nodes, it, lilvSupportedFeatureNodes)
  231. {
  232. Lilv::Node lilvFeatureNode(lilvSupportedFeatureNodes.get(it));
  233. const char* const featureURI(lilvFeatureNode.as_uri());
  234. CARLA_SAFE_ASSERT_CONTINUE(featureURI != nullptr);
  235. /**/ if (std::strcmp(featureURI, LV2_CORE__hardRTCapable) == 0)
  236. {
  237. info.hints |= CB::PLUGIN_IS_RTSAFE;
  238. }
  239. else if (std::strcmp(featureURI, LV2_INLINEDISPLAY__queue_draw) == 0)
  240. {
  241. info.hints |= CB::PLUGIN_HAS_INLINE_DISPLAY;
  242. }
  243. else if (std::strcmp(featureURI, LV2_DATA_ACCESS_URI) == 0
  244. || std::strcmp(featureURI, LV2_INSTANCE_ACCESS_URI) == 0)
  245. {
  246. carla_stderr("LV2 plugin '%s' DSP wants UI feature '%s', ignoring this", info.label, featureURI);
  247. }
  248. }
  249. lilv_nodes_free(const_cast<LilvNodes*>(lilvSupportedFeatureNodes.me));
  250. }
  251. // ----------------------------------------------------------------------------------------------------------------
  252. // category
  253. info.category = CB::PLUGIN_CATEGORY_NONE;
  254. {
  255. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  256. if (typeNodes.size() > 0)
  257. {
  258. if (typeNodes.contains(lv2World.class_allpass))
  259. info.category = CB::PLUGIN_CATEGORY_FILTER;
  260. if (typeNodes.contains(lv2World.class_amplifier))
  261. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  262. if (typeNodes.contains(lv2World.class_analyzer))
  263. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  264. if (typeNodes.contains(lv2World.class_bandpass))
  265. info.category = CB::PLUGIN_CATEGORY_FILTER;
  266. if (typeNodes.contains(lv2World.class_chorus))
  267. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  268. if (typeNodes.contains(lv2World.class_comb))
  269. info.category = CB::PLUGIN_CATEGORY_FILTER;
  270. if (typeNodes.contains(lv2World.class_compressor))
  271. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  272. if (typeNodes.contains(lv2World.class_constant))
  273. info.category = CB::PLUGIN_CATEGORY_OTHER;
  274. if (typeNodes.contains(lv2World.class_converter))
  275. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  276. if (typeNodes.contains(lv2World.class_delay))
  277. info.category = CB::PLUGIN_CATEGORY_DELAY;
  278. if (typeNodes.contains(lv2World.class_distortion))
  279. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  280. if (typeNodes.contains(lv2World.class_dynamics))
  281. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  282. if (typeNodes.contains(lv2World.class_eq))
  283. info.category = CB::PLUGIN_CATEGORY_EQ;
  284. if (typeNodes.contains(lv2World.class_envelope))
  285. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  286. if (typeNodes.contains(lv2World.class_expander))
  287. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  288. if (typeNodes.contains(lv2World.class_filter))
  289. info.category = CB::PLUGIN_CATEGORY_FILTER;
  290. if (typeNodes.contains(lv2World.class_flanger))
  291. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  292. if (typeNodes.contains(lv2World.class_function))
  293. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  294. if (typeNodes.contains(lv2World.class_gate))
  295. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  296. if (typeNodes.contains(lv2World.class_generator))
  297. info.category = CB::PLUGIN_CATEGORY_OTHER;
  298. if (typeNodes.contains(lv2World.class_highpass))
  299. info.category = CB::PLUGIN_CATEGORY_FILTER;
  300. if (typeNodes.contains(lv2World.class_limiter))
  301. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  302. if (typeNodes.contains(lv2World.class_lowpass))
  303. info.category = CB::PLUGIN_CATEGORY_FILTER;
  304. if (typeNodes.contains(lv2World.class_mixer))
  305. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  306. if (typeNodes.contains(lv2World.class_modulator))
  307. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  308. if (typeNodes.contains(lv2World.class_multiEQ))
  309. info.category = CB::PLUGIN_CATEGORY_EQ;
  310. if (typeNodes.contains(lv2World.class_oscillator))
  311. info.category = CB::PLUGIN_CATEGORY_OTHER;
  312. if (typeNodes.contains(lv2World.class_paraEQ))
  313. info.category = CB::PLUGIN_CATEGORY_EQ;
  314. if (typeNodes.contains(lv2World.class_phaser))
  315. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  316. if (typeNodes.contains(lv2World.class_pitch))
  317. info.category = CB::PLUGIN_CATEGORY_OTHER;
  318. if (typeNodes.contains(lv2World.class_reverb))
  319. info.category = CB::PLUGIN_CATEGORY_DELAY;
  320. if (typeNodes.contains(lv2World.class_simulator))
  321. info.category = CB::PLUGIN_CATEGORY_OTHER;
  322. if (typeNodes.contains(lv2World.class_spatial))
  323. info.category = CB::PLUGIN_CATEGORY_OTHER;
  324. if (typeNodes.contains(lv2World.class_spectral))
  325. info.category = CB::PLUGIN_CATEGORY_OTHER;
  326. if (typeNodes.contains(lv2World.class_utility))
  327. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  328. if (typeNodes.contains(lv2World.class_waveshaper))
  329. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  330. if (typeNodes.contains(lv2World.class_instrument))
  331. {
  332. info.category = CB::PLUGIN_CATEGORY_SYNTH;
  333. info.hints |= CB::PLUGIN_IS_SYNTH;
  334. }
  335. }
  336. lilv_nodes_free(const_cast<LilvNodes*>(typeNodes.me));
  337. }
  338. // ----------------------------------------------------------------------------------------------------------------
  339. // number data
  340. info.audioIns = 0;
  341. info.audioOuts = 0;
  342. info.cvIns = 0;
  343. info.cvOuts = 0;
  344. info.midiIns = 0;
  345. info.midiOuts = 0;
  346. info.parameterIns = 0;
  347. info.parameterOuts = 0;
  348. for (uint i=0, count=lilvPlugin.get_num_ports(); i<count; ++i)
  349. {
  350. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(i));
  351. bool isInput;
  352. /**/ if (lilvPort.is_a(lv2World.port_input))
  353. {
  354. isInput = true;
  355. }
  356. else if (lilvPort.is_a(lv2World.port_output))
  357. {
  358. isInput = false;
  359. }
  360. else
  361. {
  362. const LilvNode* const symbolNode = lilvPort.get_symbol();
  363. CARLA_SAFE_ASSERT_CONTINUE(symbolNode != nullptr && lilv_node_is_string(symbolNode));
  364. const char* const symbol = lilv_node_as_string(symbolNode);
  365. CARLA_SAFE_ASSERT_CONTINUE(symbol != nullptr);
  366. carla_stderr("LV2 plugin '%s' port '%s' is neither input or output", info.label, symbol);
  367. continue;
  368. }
  369. /**/ if (lilvPort.is_a(lv2World.port_control))
  370. {
  371. // skip some control ports
  372. if (lilvPort.has_property(lv2World.reportsLatency))
  373. continue;
  374. if (LilvNode* const designationNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.designation.me))
  375. {
  376. bool skip = false;
  377. if (const char* const designation = lilv_node_as_string(designationNode))
  378. {
  379. /**/ if (std::strcmp(designation, LV2_CORE__control) == 0)
  380. skip = true;
  381. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  382. skip = true;
  383. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  384. skip = true;
  385. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  386. skip = true;
  387. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  388. skip = true;
  389. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  390. skip = true;
  391. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  392. skip = true;
  393. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  394. skip = true;
  395. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  396. skip = true;
  397. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  398. skip = true;
  399. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  400. skip = true;
  401. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  402. skip = true;
  403. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  404. skip = true;
  405. else if (std::strcmp(designation, LV2_KXSTUDIO_PROPERTIES__TimePositionTicksPerBeat) == 0)
  406. skip = true;
  407. }
  408. lilv_node_free(designationNode);
  409. if (skip)
  410. continue;
  411. }
  412. if (isInput)
  413. ++(info.parameterIns);
  414. else
  415. ++(info.parameterOuts);
  416. }
  417. else if (lilvPort.is_a(lv2World.port_audio))
  418. {
  419. if (isInput)
  420. ++(info.audioIns);
  421. else
  422. ++(info.audioOuts);
  423. }
  424. else if (lilvPort.is_a(lv2World.port_cv))
  425. {
  426. if (isInput)
  427. ++(info.cvIns);
  428. else
  429. ++(info.cvOuts);
  430. }
  431. else if (lilvPort.is_a(lv2World.port_atom))
  432. {
  433. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  434. for (LilvIter *it = lilv_nodes_begin(supportNodes.me); ! lilv_nodes_is_end(supportNodes.me, it); it = lilv_nodes_next(supportNodes.me, it))
  435. {
  436. const Lilv::Node node(lilv_nodes_get(supportNodes.me, it));
  437. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  438. if (node.equals(lv2World.midi_event))
  439. {
  440. if (isInput)
  441. ++(info.midiIns);
  442. else
  443. ++(info.midiOuts);
  444. }
  445. }
  446. lilv_nodes_free(const_cast<LilvNodes*>(supportNodes.me));
  447. }
  448. else if (lilvPort.is_a(lv2World.port_event))
  449. {
  450. if (lilvPort.supports_event(lv2World.midi_event))
  451. {
  452. if (isInput)
  453. ++(info.midiIns);
  454. else
  455. ++(info.midiOuts);
  456. }
  457. }
  458. else if (lilvPort.is_a(lv2World.port_midi))
  459. {
  460. if (isInput)
  461. ++(info.midiIns);
  462. else
  463. ++(info.midiOuts);
  464. }
  465. else
  466. {
  467. const LilvNode* const symbolNode = lilvPort.get_symbol();
  468. CARLA_SAFE_ASSERT_CONTINUE(symbolNode != nullptr && lilv_node_is_string(symbolNode));
  469. const char* const symbol = lilv_node_as_string(symbolNode);
  470. CARLA_SAFE_ASSERT_CONTINUE(symbol != nullptr);
  471. supported = false;
  472. carla_stderr("LV2 plugin '%s' port '%s' is required but has unsupported type", info.label, symbol);
  473. }
  474. }
  475. if (supported)
  476. info.valid = true;
  477. return &info;
  478. }
  479. // -------------------------------------------------------------------------------------------------------------------
  480. #if defined(USING_JUCE) && defined(CARLA_OS_MAC)
  481. static juce::StringArray gCachedAuPluginResults;
  482. static void findAUs()
  483. {
  484. if (gCachedAuPluginResults.size() != 0)
  485. return;
  486. juce::AudioUnitPluginFormat auFormat;
  487. gCachedAuPluginResults = auFormat.searchPathsForPlugins(juce::FileSearchPath(), false, false);
  488. }
  489. static const CarlaCachedPluginInfo* get_cached_plugin_au(const juce::String pluginId)
  490. {
  491. static CarlaCachedPluginInfo info;
  492. static CarlaString sname, slabel, smaker;
  493. info.valid = false;
  494. juce::AudioUnitPluginFormat auFormat;
  495. juce::OwnedArray<juce::PluginDescription> results;
  496. auFormat.findAllTypesForFile(results, pluginId);
  497. CARLA_SAFE_ASSERT_RETURN(results.size() > 0, &info);
  498. CARLA_SAFE_ASSERT(results.size() == 1);
  499. juce::PluginDescription* const desc(results[0]);
  500. CARLA_SAFE_ASSERT_RETURN(desc != nullptr, &info);
  501. info.category = CB::getPluginCategoryFromName(desc->category.toRawUTF8());
  502. info.hints = 0x0;
  503. info.valid = true;
  504. if (desc->isInstrument)
  505. info.hints |= CB::PLUGIN_IS_SYNTH;
  506. if (true)
  507. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  508. info.audioIns = static_cast<uint32_t>(desc->numInputChannels);
  509. info.audioOuts = static_cast<uint32_t>(desc->numOutputChannels);
  510. info.cvIns = 0;
  511. info.cvOuts = 0;
  512. info.midiIns = desc->isInstrument ? 1 : 0;
  513. info.midiOuts = 0;
  514. info.parameterIns = 0;
  515. info.parameterOuts = 0;
  516. sname = desc->name.toRawUTF8();
  517. slabel = desc->fileOrIdentifier.toRawUTF8();
  518. smaker = desc->manufacturerName.toRawUTF8();
  519. info.name = sname;
  520. info.label = slabel;
  521. info.maker = smaker;
  522. info.copyright = gCachedPluginsNullCharPtr;
  523. return &info;
  524. }
  525. #endif
  526. // -------------------------------------------------------------------------------------------------------------------
  527. static const CarlaCachedPluginInfo* get_cached_plugin_sfz(const water::File& file)
  528. {
  529. static CarlaCachedPluginInfo info;
  530. static CarlaString name, filename;
  531. name = file.getFileNameWithoutExtension().toRawUTF8();
  532. name.replace('_',' ');
  533. filename = file.getFullPathName().toRawUTF8();
  534. info.category = CB::PLUGIN_CATEGORY_SYNTH;
  535. info.hints = CB::PLUGIN_IS_SYNTH;
  536. // CB::PLUGIN_IS_RTSAFE
  537. info.valid = true;
  538. info.audioIns = 0;
  539. info.audioOuts = 2;
  540. info.cvIns = 0;
  541. info.cvOuts = 0;
  542. info.midiIns = 1;
  543. info.midiOuts = 0;
  544. info.parameterIns = 0;
  545. info.parameterOuts = 1;
  546. info.name = name.buffer();
  547. info.label = filename.buffer();
  548. info.maker = gCachedPluginsNullCharPtr;
  549. info.copyright = gCachedPluginsNullCharPtr;
  550. return &info;
  551. }
  552. // -------------------------------------------------------------------------------------------------------------------
  553. static const CarlaCachedPluginInfo* get_cached_plugin_jsfx(const water::File& file)
  554. {
  555. static CarlaCachedPluginInfo info;
  556. JsusFx::init();
  557. CarlaJsusFxPathLibrary pathLibrary(file);
  558. CarlaJsusFx effect(pathLibrary);
  559. effect.setQuiet(true);
  560. static CarlaString name, filename;
  561. name = file.getFileNameWithoutExtension().toRawUTF8();
  562. filename = file.getFullPathName().toRawUTF8();
  563. {
  564. const CarlaScopedLocale csl;
  565. if (!effect.readHeader(pathLibrary, filename.buffer()))
  566. {
  567. info.valid = false;
  568. return &info;
  569. }
  570. }
  571. if (effect.desc[0] == '\0')
  572. {
  573. info.valid = false;
  574. return &info;
  575. }
  576. info.valid = true;
  577. // NOTE: count can be -1 in case of "none"
  578. info.audioIns = (effect.numInputs == -1) ? 0 : (uint32_t)effect.numInputs;
  579. info.audioOuts = (effect.numOutputs == -1) ? 0 : (uint32_t)effect.numOutputs;
  580. info.cvIns = 0;
  581. info.cvOuts = 0;
  582. info.midiIns = 1;
  583. info.midiOuts = 1;
  584. info.parameterIns = 0;
  585. info.parameterOuts = 0;
  586. for (uint32_t sliderIndex = 0; sliderIndex < JsusFx::kMaxSliders; ++sliderIndex)
  587. {
  588. if (effect.sliders[sliderIndex].exists)
  589. ++info.parameterIns;
  590. }
  591. info.category = CB::PLUGIN_CATEGORY_NONE;
  592. info.hints = 0;
  593. #if 0 // TODO(jsfx) when supporting custom graphics
  594. if (effect.hasGraphicsSection())
  595. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  596. // TODO(jsfx) there should be a way to check this without compiling
  597. #endif
  598. info.name = name.buffer();
  599. info.label = filename.buffer();
  600. info.maker = gCachedPluginsNullCharPtr;
  601. info.copyright = gCachedPluginsNullCharPtr;
  602. return &info;
  603. }
  604. // -------------------------------------------------------------------------------------------------------------------
  605. uint carla_get_cached_plugin_count(CB::PluginType ptype, const char* pluginPath)
  606. {
  607. CARLA_SAFE_ASSERT_RETURN(isCachedPluginType(ptype), 0);
  608. carla_debug("carla_get_cached_plugin_count(%i:%s, %s)", ptype, CB::PluginType2Str(ptype), pluginPath);
  609. switch (ptype)
  610. {
  611. case CB::PLUGIN_INTERNAL: {
  612. uint32_t count = 0;
  613. carla_get_native_plugins_data(&count);
  614. return count;
  615. }
  616. case CB::PLUGIN_LV2: {
  617. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  618. lv2World.initIfNeeded(pluginPath);
  619. return lv2World.getPluginCount();
  620. }
  621. #if defined(USING_JUCE) && defined(CARLA_OS_MAC)
  622. case CB::PLUGIN_AU: {
  623. findAUs();
  624. return static_cast<uint>(gCachedAuPluginResults.size());
  625. }
  626. #endif
  627. case CB::PLUGIN_SFZ: {
  628. findSFZs(pluginPath);
  629. return static_cast<uint>(gSFZs.size());
  630. }
  631. case CB::PLUGIN_JSFX: {
  632. findJSFXs(pluginPath);
  633. return static_cast<uint>(gJSFXs.size());
  634. }
  635. default:
  636. return 0;
  637. }
  638. }
  639. const CarlaCachedPluginInfo* carla_get_cached_plugin_info(CB::PluginType ptype, uint index)
  640. {
  641. carla_debug("carla_get_cached_plugin_info(%i:%s, %i)", ptype, CB::PluginType2Str(ptype), index);
  642. switch (ptype)
  643. {
  644. case CB::PLUGIN_INTERNAL: {
  645. uint32_t count = 0;
  646. const NativePluginDescriptor* const descs(carla_get_native_plugins_data(&count));
  647. CARLA_SAFE_ASSERT_BREAK(index < count);
  648. CARLA_SAFE_ASSERT_BREAK(descs != nullptr);
  649. const NativePluginDescriptor& desc(descs[index]);
  650. return get_cached_plugin_internal(desc);
  651. }
  652. case CB::PLUGIN_LV2: {
  653. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  654. const LilvPlugin* const cPlugin(lv2World.getPluginFromIndex(index));
  655. CARLA_SAFE_ASSERT_BREAK(cPlugin != nullptr);
  656. Lilv::Plugin lilvPlugin(cPlugin);
  657. CARLA_SAFE_ASSERT_BREAK(lilvPlugin.get_uri().is_uri());
  658. return get_cached_plugin_lv2(lv2World, lilvPlugin);
  659. }
  660. #if defined(USING_JUCE) && defined(CARLA_OS_MAC)
  661. case CB::PLUGIN_AU: {
  662. CARLA_SAFE_ASSERT_BREAK(index < static_cast<uint>(gCachedAuPluginResults.size()));
  663. return get_cached_plugin_au(gCachedAuPluginResults.strings.getUnchecked(static_cast<int>(index)));
  664. }
  665. #endif
  666. case CB::PLUGIN_SFZ: {
  667. CARLA_SAFE_ASSERT_BREAK(index < static_cast<uint>(gSFZs.size()));
  668. return get_cached_plugin_sfz(gSFZs.getUnchecked(static_cast<int>(index)));
  669. }
  670. case CB::PLUGIN_JSFX: {
  671. CARLA_SAFE_ASSERT_BREAK(index < static_cast<uint>(gJSFXs.size()));
  672. return get_cached_plugin_jsfx(gJSFXs.getUnchecked(static_cast<int>(index)));
  673. }
  674. default:
  675. break;
  676. }
  677. static CarlaCachedPluginInfo info;
  678. return &info;
  679. }
  680. // -------------------------------------------------------------------------------------------------------------------
  681. #ifndef CARLA_PLUGIN_EXPORT
  682. # include "../native-plugins/_data.cpp"
  683. #endif
  684. // -------------------------------------------------------------------------------------------------------------------