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.

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