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.

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