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.

700 lines
25KB

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