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.

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