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.

791 lines
27KB

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