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.

801 lines
28KB

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