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.

CachedPlugins.cpp 23KB

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