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 29KB

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