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.

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