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.

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