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.

721 lines
25KB

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