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.

790 lines
27KB

  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;
  213. break;
  214. }
  215. }
  216. }
  217. #ifdef CARLA_OS_LINUX
  218. else if (lilvPlugin.get_modgui_resources_directory().as_uri() != nullptr)
  219. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  220. #endif
  221. lilv_nodes_free(const_cast<LilvNodes*>(lilvUIs.me));
  222. }
  223. {
  224. Lilv::Nodes lilvRequiredFeatureNodes(lilvPlugin.get_required_features());
  225. LILV_FOREACH(nodes, it, lilvRequiredFeatureNodes)
  226. {
  227. Lilv::Node lilvFeatureNode(lilvRequiredFeatureNodes.get(it));
  228. const char* const featureURI(lilvFeatureNode.as_uri());
  229. CARLA_SAFE_ASSERT_CONTINUE(featureURI != nullptr);
  230. if (! is_lv2_feature_supported(featureURI))
  231. {
  232. if (std::strcmp(featureURI, LV2_DATA_ACCESS_URI) == 0
  233. || std::strcmp(featureURI, LV2_INSTANCE_ACCESS_URI) == 0)
  234. {
  235. // we give a warning about this below
  236. continue;
  237. }
  238. supported = false;
  239. carla_stderr("LV2 plugin '%s' requires unsupported feature '%s'", info.label, featureURI);
  240. }
  241. }
  242. lilv_nodes_free(const_cast<LilvNodes*>(lilvRequiredFeatureNodes.me));
  243. }
  244. {
  245. Lilv::Nodes lilvSupportedFeatureNodes(lilvPlugin.get_supported_features());
  246. LILV_FOREACH(nodes, it, lilvSupportedFeatureNodes)
  247. {
  248. Lilv::Node lilvFeatureNode(lilvSupportedFeatureNodes.get(it));
  249. const char* const featureURI(lilvFeatureNode.as_uri());
  250. CARLA_SAFE_ASSERT_CONTINUE(featureURI != nullptr);
  251. /**/ if (std::strcmp(featureURI, LV2_CORE__hardRTCapable) == 0)
  252. {
  253. info.hints |= CB::PLUGIN_IS_RTSAFE;
  254. }
  255. else if (std::strcmp(featureURI, LV2_INLINEDISPLAY__queue_draw) == 0)
  256. {
  257. info.hints |= CB::PLUGIN_HAS_INLINE_DISPLAY;
  258. }
  259. else if (std::strcmp(featureURI, LV2_DATA_ACCESS_URI) == 0
  260. || std::strcmp(featureURI, LV2_INSTANCE_ACCESS_URI) == 0)
  261. {
  262. carla_stderr("LV2 plugin '%s' DSP wants UI feature '%s', ignoring this", info.label, featureURI);
  263. }
  264. }
  265. lilv_nodes_free(const_cast<LilvNodes*>(lilvSupportedFeatureNodes.me));
  266. }
  267. // ----------------------------------------------------------------------------------------------------------------
  268. // category
  269. info.category = CB::PLUGIN_CATEGORY_NONE;
  270. {
  271. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  272. if (typeNodes.size() > 0)
  273. {
  274. if (typeNodes.contains(lv2World.class_allpass))
  275. info.category = CB::PLUGIN_CATEGORY_FILTER;
  276. if (typeNodes.contains(lv2World.class_amplifier))
  277. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  278. if (typeNodes.contains(lv2World.class_analyzer))
  279. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  280. if (typeNodes.contains(lv2World.class_bandpass))
  281. info.category = CB::PLUGIN_CATEGORY_FILTER;
  282. if (typeNodes.contains(lv2World.class_chorus))
  283. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  284. if (typeNodes.contains(lv2World.class_comb))
  285. info.category = CB::PLUGIN_CATEGORY_FILTER;
  286. if (typeNodes.contains(lv2World.class_compressor))
  287. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  288. if (typeNodes.contains(lv2World.class_constant))
  289. info.category = CB::PLUGIN_CATEGORY_OTHER;
  290. if (typeNodes.contains(lv2World.class_converter))
  291. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  292. if (typeNodes.contains(lv2World.class_delay))
  293. info.category = CB::PLUGIN_CATEGORY_DELAY;
  294. if (typeNodes.contains(lv2World.class_distortion))
  295. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  296. if (typeNodes.contains(lv2World.class_dynamics))
  297. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  298. if (typeNodes.contains(lv2World.class_eq))
  299. info.category = CB::PLUGIN_CATEGORY_EQ;
  300. if (typeNodes.contains(lv2World.class_envelope))
  301. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  302. if (typeNodes.contains(lv2World.class_expander))
  303. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  304. if (typeNodes.contains(lv2World.class_filter))
  305. info.category = CB::PLUGIN_CATEGORY_FILTER;
  306. if (typeNodes.contains(lv2World.class_flanger))
  307. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  308. if (typeNodes.contains(lv2World.class_function))
  309. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  310. if (typeNodes.contains(lv2World.class_gate))
  311. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  312. if (typeNodes.contains(lv2World.class_generator))
  313. info.category = CB::PLUGIN_CATEGORY_OTHER;
  314. if (typeNodes.contains(lv2World.class_highpass))
  315. info.category = CB::PLUGIN_CATEGORY_FILTER;
  316. if (typeNodes.contains(lv2World.class_limiter))
  317. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  318. if (typeNodes.contains(lv2World.class_lowpass))
  319. info.category = CB::PLUGIN_CATEGORY_FILTER;
  320. if (typeNodes.contains(lv2World.class_mixer))
  321. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  322. if (typeNodes.contains(lv2World.class_modulator))
  323. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  324. if (typeNodes.contains(lv2World.class_multiEQ))
  325. info.category = CB::PLUGIN_CATEGORY_EQ;
  326. if (typeNodes.contains(lv2World.class_oscillator))
  327. info.category = CB::PLUGIN_CATEGORY_OTHER;
  328. if (typeNodes.contains(lv2World.class_paraEQ))
  329. info.category = CB::PLUGIN_CATEGORY_EQ;
  330. if (typeNodes.contains(lv2World.class_phaser))
  331. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  332. if (typeNodes.contains(lv2World.class_pitch))
  333. info.category = CB::PLUGIN_CATEGORY_OTHER;
  334. if (typeNodes.contains(lv2World.class_reverb))
  335. info.category = CB::PLUGIN_CATEGORY_DELAY;
  336. if (typeNodes.contains(lv2World.class_simulator))
  337. info.category = CB::PLUGIN_CATEGORY_OTHER;
  338. if (typeNodes.contains(lv2World.class_spatial))
  339. info.category = CB::PLUGIN_CATEGORY_OTHER;
  340. if (typeNodes.contains(lv2World.class_spectral))
  341. info.category = CB::PLUGIN_CATEGORY_OTHER;
  342. if (typeNodes.contains(lv2World.class_utility))
  343. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  344. if (typeNodes.contains(lv2World.class_waveshaper))
  345. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  346. if (typeNodes.contains(lv2World.class_instrument))
  347. {
  348. info.category = CB::PLUGIN_CATEGORY_SYNTH;
  349. info.hints |= CB::PLUGIN_IS_SYNTH;
  350. }
  351. }
  352. lilv_nodes_free(const_cast<LilvNodes*>(typeNodes.me));
  353. }
  354. // ----------------------------------------------------------------------------------------------------------------
  355. // number data
  356. info.audioIns = 0;
  357. info.audioOuts = 0;
  358. info.cvIns = 0;
  359. info.cvOuts = 0;
  360. info.midiIns = 0;
  361. info.midiOuts = 0;
  362. info.parameterIns = 0;
  363. info.parameterOuts = 0;
  364. for (uint i=0, count=lilvPlugin.get_num_ports(); i<count; ++i)
  365. {
  366. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(i));
  367. bool isInput;
  368. /**/ if (lilvPort.is_a(lv2World.port_input))
  369. {
  370. isInput = true;
  371. }
  372. else if (lilvPort.is_a(lv2World.port_output))
  373. {
  374. isInput = false;
  375. }
  376. else
  377. {
  378. const LilvNode* const symbolNode = lilvPort.get_symbol();
  379. CARLA_SAFE_ASSERT_CONTINUE(symbolNode != nullptr && lilv_node_is_string(symbolNode));
  380. const char* const symbol = lilv_node_as_string(symbolNode);
  381. CARLA_SAFE_ASSERT_CONTINUE(symbol != nullptr);
  382. carla_stderr("LV2 plugin '%s' port '%s' is neither input or output", info.label, symbol);
  383. continue;
  384. }
  385. /**/ if (lilvPort.is_a(lv2World.port_control))
  386. {
  387. // skip some control ports
  388. if (lilvPort.has_property(lv2World.reportsLatency))
  389. continue;
  390. if (LilvNode* const designationNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.designation.me))
  391. {
  392. bool skip = false;
  393. if (const char* const designation = lilv_node_as_string(designationNode))
  394. {
  395. /**/ if (std::strcmp(designation, LV2_CORE__control) == 0)
  396. skip = true;
  397. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  398. skip = true;
  399. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  400. skip = true;
  401. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  402. skip = true;
  403. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  404. skip = true;
  405. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  406. skip = true;
  407. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  408. skip = true;
  409. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  410. skip = true;
  411. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  412. skip = true;
  413. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  414. skip = true;
  415. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  416. skip = true;
  417. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  418. skip = true;
  419. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  420. skip = true;
  421. else if (std::strcmp(designation, LV2_KXSTUDIO_PROPERTIES__TimePositionTicksPerBeat) == 0)
  422. skip = true;
  423. }
  424. lilv_node_free(designationNode);
  425. if (skip)
  426. continue;
  427. }
  428. if (isInput)
  429. ++(info.parameterIns);
  430. else
  431. ++(info.parameterOuts);
  432. }
  433. else if (lilvPort.is_a(lv2World.port_audio))
  434. {
  435. if (isInput)
  436. ++(info.audioIns);
  437. else
  438. ++(info.audioOuts);
  439. }
  440. else if (lilvPort.is_a(lv2World.port_cv))
  441. {
  442. if (isInput)
  443. ++(info.cvIns);
  444. else
  445. ++(info.cvOuts);
  446. }
  447. else if (lilvPort.is_a(lv2World.port_atom))
  448. {
  449. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  450. for (LilvIter *it = lilv_nodes_begin(supportNodes.me); ! lilv_nodes_is_end(supportNodes.me, it); it = lilv_nodes_next(supportNodes.me, it))
  451. {
  452. const Lilv::Node node(lilv_nodes_get(supportNodes.me, it));
  453. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  454. if (node.equals(lv2World.midi_event))
  455. {
  456. if (isInput)
  457. ++(info.midiIns);
  458. else
  459. ++(info.midiOuts);
  460. }
  461. }
  462. lilv_nodes_free(const_cast<LilvNodes*>(supportNodes.me));
  463. }
  464. else if (lilvPort.is_a(lv2World.port_event))
  465. {
  466. if (lilvPort.supports_event(lv2World.midi_event))
  467. {
  468. if (isInput)
  469. ++(info.midiIns);
  470. else
  471. ++(info.midiOuts);
  472. }
  473. }
  474. else if (lilvPort.is_a(lv2World.port_midi))
  475. {
  476. if (isInput)
  477. ++(info.midiIns);
  478. else
  479. ++(info.midiOuts);
  480. }
  481. else
  482. {
  483. const LilvNode* const symbolNode = lilvPort.get_symbol();
  484. CARLA_SAFE_ASSERT_CONTINUE(symbolNode != nullptr && lilv_node_is_string(symbolNode));
  485. const char* const symbol = lilv_node_as_string(symbolNode);
  486. CARLA_SAFE_ASSERT_CONTINUE(symbol != nullptr);
  487. supported = false;
  488. carla_stderr("LV2 plugin '%s' port '%s' is required but has unsupported type", info.label, symbol);
  489. }
  490. }
  491. if (supported)
  492. info.valid = true;
  493. return &info;
  494. }
  495. // -------------------------------------------------------------------------------------------------------------------
  496. #ifdef HAVE_SFZ
  497. static const CarlaCachedPluginInfo* get_cached_plugin_sfz(const water::File& file)
  498. {
  499. static CarlaCachedPluginInfo info;
  500. static String name, filename;
  501. name = file.getFileNameWithoutExtension().toRawUTF8();
  502. name.replace('_',' ');
  503. filename = file.getFullPathName().toRawUTF8();
  504. info.category = CB::PLUGIN_CATEGORY_SYNTH;
  505. info.hints = CB::PLUGIN_IS_SYNTH;
  506. // CB::PLUGIN_IS_RTSAFE
  507. info.valid = true;
  508. info.audioIns = 0;
  509. info.audioOuts = 2;
  510. info.cvIns = 0;
  511. info.cvOuts = 0;
  512. info.midiIns = 1;
  513. info.midiOuts = 0;
  514. info.parameterIns = 0;
  515. info.parameterOuts = 1;
  516. info.name = name.buffer();
  517. info.label = filename.buffer();
  518. info.maker = gCachedPluginsNullCharPtr;
  519. info.copyright = gCachedPluginsNullCharPtr;
  520. return &info;
  521. }
  522. #endif
  523. // -------------------------------------------------------------------------------------------------------------------
  524. #ifdef HAVE_YSFX
  525. static const CarlaCachedPluginInfo* get_cached_plugin_jsfx(const CB::CarlaJsfxUnit& unit)
  526. {
  527. static CarlaCachedPluginInfo info;
  528. ysfx_config_u config(ysfx_config_new());
  529. const String rootPath = unit.getRootPath();
  530. const String filePath = unit.getFilePath();
  531. ysfx_register_builtin_audio_formats(config.get());
  532. ysfx_set_import_root(config.get(), rootPath);
  533. ysfx_guess_file_roots(config.get(), filePath);
  534. ysfx_set_log_reporter(config.get(), &CB::CarlaJsfxLogging::logErrorsOnly);
  535. ysfx_u effect(ysfx_new(config.get()));
  536. if (! ysfx_load_file(effect.get(), filePath, 0))
  537. {
  538. info.valid = false;
  539. return &info;
  540. }
  541. // plugins with neither @block nor @sample are valid, but they are useless
  542. // also use this as a sanity check against misdetected files
  543. // since JSFX parsing is so permissive, it might accept lambda text files
  544. if (! ysfx_has_section(effect.get(), ysfx_section_block) &&
  545. ! ysfx_has_section(effect.get(), ysfx_section_sample))
  546. {
  547. info.valid = false;
  548. return &info;
  549. }
  550. static String name, label, maker;
  551. label = unit.getFileId();
  552. name = ysfx_get_name(effect.get());
  553. maker = ysfx_get_author(effect.get());
  554. info.valid = true;
  555. info.category = CB::CarlaJsfxCategories::getFromEffect(effect.get());
  556. info.audioIns = ysfx_get_num_inputs(effect.get());
  557. info.audioOuts = ysfx_get_num_outputs(effect.get());
  558. info.cvIns = 0;
  559. info.cvOuts = 0;
  560. info.midiIns = 1;
  561. info.midiOuts = 1;
  562. info.parameterIns = 0;
  563. info.parameterOuts = 0;
  564. for (uint32_t sliderIndex = 0; sliderIndex < ysfx_max_sliders; ++sliderIndex)
  565. {
  566. if (ysfx_slider_exists(effect.get(), sliderIndex))
  567. ++info.parameterIns;
  568. }
  569. info.hints = 0;
  570. #if 0 // TODO(jsfx) when supporting custom graphics
  571. if (ysfx_has_section(effect.get(), ysfx_section_gfx))
  572. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  573. #endif
  574. info.name = name.buffer();
  575. info.label = label.buffer();
  576. info.maker = maker.buffer();
  577. info.copyright = gCachedPluginsNullCharPtr;
  578. return &info;
  579. }
  580. #endif
  581. // -------------------------------------------------------------------------------------------------------------------
  582. uint carla_get_cached_plugin_count(CB::PluginType ptype, const char* pluginPath)
  583. {
  584. CARLA_SAFE_ASSERT_RETURN(isCachedPluginType(ptype), 0);
  585. carla_debug("carla_get_cached_plugin_count(%i:%s, %s)", ptype, CB::PluginType2Str(ptype), pluginPath);
  586. switch (ptype)
  587. {
  588. case CB::PLUGIN_INTERNAL: {
  589. uint32_t count = 0;
  590. carla_get_native_plugins_data(&count);
  591. return count;
  592. }
  593. case CB::PLUGIN_LV2: {
  594. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  595. lv2World.initIfNeeded(pluginPath);
  596. return lv2World.getPluginCount();
  597. }
  598. #ifdef HAVE_SFZ
  599. case CB::PLUGIN_SFZ:
  600. findSFZs(pluginPath);
  601. return static_cast<uint>(gSFZs.size());
  602. #endif
  603. #ifdef HAVE_YSFX
  604. case CB::PLUGIN_JSFX:
  605. findJSFXs(pluginPath);
  606. return static_cast<uint>(gJSFXs.size());
  607. #endif
  608. default:
  609. return 0;
  610. }
  611. }
  612. const CarlaCachedPluginInfo* carla_get_cached_plugin_info(CB::PluginType ptype, uint index)
  613. {
  614. carla_debug("carla_get_cached_plugin_info(%i:%s, %i)", ptype, CB::PluginType2Str(ptype), index);
  615. switch (ptype)
  616. {
  617. case CB::PLUGIN_INTERNAL: {
  618. uint32_t count = 0;
  619. const NativePluginDescriptor* const descs(carla_get_native_plugins_data(&count));
  620. CARLA_SAFE_ASSERT_BREAK(index < count);
  621. CARLA_SAFE_ASSERT_BREAK(descs != nullptr);
  622. const NativePluginDescriptor& desc(descs[index]);
  623. return get_cached_plugin_internal(desc);
  624. }
  625. case CB::PLUGIN_LV2: {
  626. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  627. const LilvPlugin* const cPlugin(lv2World.getPluginFromIndex(index));
  628. CARLA_SAFE_ASSERT_BREAK(cPlugin != nullptr);
  629. Lilv::Plugin lilvPlugin(cPlugin);
  630. CARLA_SAFE_ASSERT_BREAK(lilvPlugin.get_uri().is_uri());
  631. return get_cached_plugin_lv2(lv2World, lilvPlugin);
  632. }
  633. #ifdef HAVE_SFZ
  634. case CB::PLUGIN_SFZ:
  635. CARLA_SAFE_ASSERT_BREAK(index < gSFZs.size());
  636. return get_cached_plugin_sfz(gSFZs[index]);
  637. #endif
  638. #ifdef HAVE_YSFX
  639. case CB::PLUGIN_JSFX:
  640. CARLA_SAFE_ASSERT_BREAK(index < static_cast<uint>(gJSFXs.size()));
  641. return get_cached_plugin_jsfx(gJSFXs[index]);
  642. #endif
  643. default:
  644. break;
  645. }
  646. static CarlaCachedPluginInfo info;
  647. return &info;
  648. }
  649. // -------------------------------------------------------------------------------------------------------------------
  650. #ifndef CARLA_PLUGIN_BUILD
  651. # include "../native-plugins/_data.cpp"
  652. #endif
  653. // -------------------------------------------------------------------------------------------------------------------