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.

703 lines
25KB

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