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.

685 lines
24KB

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