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.

852 lines
29KB

  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. #include "CarlaJsfxUtils.hpp"
  23. #if defined(USING_JUCE) && defined(CARLA_OS_MAC)
  24. # include "AppConfig.h"
  25. # include "juce_audio_processors/juce_audio_processors.h"
  26. #endif
  27. #include "water/containers/Array.h"
  28. #include "water/files/File.h"
  29. namespace CB = CARLA_BACKEND_NAMESPACE;
  30. // -------------------------------------------------------------------------------------------------------------------
  31. static const char* const gCachedPluginsNullCharPtr = "";
  32. static bool isCachedPluginType(const CB::PluginType ptype)
  33. {
  34. switch (ptype)
  35. {
  36. case CB::PLUGIN_INTERNAL:
  37. case CB::PLUGIN_LV2:
  38. case CB::PLUGIN_AU:
  39. case CB::PLUGIN_SFZ:
  40. case CB::PLUGIN_JSFX:
  41. return true;
  42. default:
  43. return false;
  44. }
  45. }
  46. // -------------------------------------------------------------------------------------------------------------------
  47. _CarlaCachedPluginInfo::_CarlaCachedPluginInfo() noexcept
  48. : valid(false),
  49. category(CB::PLUGIN_CATEGORY_NONE),
  50. hints(0x0),
  51. audioIns(0),
  52. audioOuts(0),
  53. cvIns(0),
  54. cvOuts(0),
  55. midiIns(0),
  56. midiOuts(0),
  57. parameterIns(0),
  58. parameterOuts(0),
  59. name(gCachedPluginsNullCharPtr),
  60. label(gCachedPluginsNullCharPtr),
  61. maker(gCachedPluginsNullCharPtr),
  62. copyright(gCachedPluginsNullCharPtr) {}
  63. // -------------------------------------------------------------------------------------------------------------------
  64. static std::vector<water::File> gSFZs;
  65. static void findSFZs(const char* const sfzPaths)
  66. {
  67. gSFZs.clear();
  68. CARLA_SAFE_ASSERT_RETURN(sfzPaths != nullptr,);
  69. if (sfzPaths[0] == '\0')
  70. return;
  71. const water::StringArray splitPaths(water::StringArray::fromTokens(sfzPaths, CARLA_OS_SPLIT_STR, ""));
  72. for (water::String *it = splitPaths.begin(), *end = splitPaths.end(); it != end; ++it)
  73. {
  74. std::vector<water::File> results;
  75. if (water::File(*it).findChildFiles(results, water::File::findFiles|water::File::ignoreHiddenFiles, true, "*.sfz") > 0)
  76. {
  77. gSFZs.reserve(gSFZs.size() + results.size());
  78. gSFZs.insert(gSFZs.end(), results.begin(), results.end());
  79. }
  80. }
  81. }
  82. // -------------------------------------------------------------------------------------------------------------------
  83. #ifdef HAVE_YSFX
  84. static std::vector<CB::CarlaJsfxUnit> gJSFXs;
  85. static void findJSFXs(const char* const jsfxPaths)
  86. {
  87. gJSFXs.clear();
  88. CARLA_SAFE_ASSERT_RETURN(jsfxPaths != nullptr,);
  89. if (jsfxPaths[0] == '\0')
  90. return;
  91. const water::StringArray splitPaths(water::StringArray::fromTokens(jsfxPaths, CARLA_OS_SPLIT_STR, ""));
  92. for (water::String *it = splitPaths.begin(), *end = splitPaths.end(); it != end; ++it)
  93. {
  94. std::vector<water::File> results;
  95. const water::File path(*it);
  96. if (path.findChildFiles(results, water::File::findFiles|water::File::ignoreHiddenFiles, true, "*") > 0)
  97. {
  98. gJSFXs.reserve(gJSFXs.size() + results.size());
  99. for (std::vector<water::File>::iterator it2=results.begin(), end2=results.end(); it2 != end2; ++it2)
  100. {
  101. const water::File& file(*it2);
  102. const water::String fileExt = file.getFileExtension();
  103. if (fileExt.isEmpty() || fileExt.equalsIgnoreCase(".jsfx"))
  104. gJSFXs.push_back(CB::CarlaJsfxUnit(path, file));
  105. }
  106. }
  107. }
  108. }
  109. #endif
  110. // -------------------------------------------------------------------------------------------------------------------
  111. static const CarlaCachedPluginInfo* get_cached_plugin_internal(const NativePluginDescriptor& desc)
  112. {
  113. static CarlaCachedPluginInfo info;
  114. info.category = static_cast<CB::PluginCategory>(desc.category);
  115. info.hints = 0x0;
  116. if (desc.hints & NATIVE_PLUGIN_IS_RTSAFE)
  117. info.hints |= CB::PLUGIN_IS_RTSAFE;
  118. if (desc.hints & NATIVE_PLUGIN_IS_SYNTH)
  119. info.hints |= CB::PLUGIN_IS_SYNTH;
  120. if (desc.hints & NATIVE_PLUGIN_HAS_UI)
  121. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  122. if (desc.hints & NATIVE_PLUGIN_HAS_INLINE_DISPLAY)
  123. info.hints |= CB::PLUGIN_HAS_INLINE_DISPLAY;
  124. if (desc.hints & NATIVE_PLUGIN_NEEDS_FIXED_BUFFERS)
  125. info.hints |= CB::PLUGIN_NEEDS_FIXED_BUFFERS;
  126. if (desc.hints & NATIVE_PLUGIN_NEEDS_UI_MAIN_THREAD)
  127. info.hints |= CB::PLUGIN_NEEDS_UI_MAIN_THREAD;
  128. if (desc.hints & NATIVE_PLUGIN_USES_MULTI_PROGS)
  129. info.hints |= CB::PLUGIN_USES_MULTI_PROGS;
  130. info.valid = true;
  131. info.audioIns = desc.audioIns;
  132. info.audioOuts = desc.audioOuts;
  133. info.cvIns = desc.cvIns;
  134. info.cvOuts = desc.cvOuts;
  135. info.midiIns = desc.midiIns;
  136. info.midiOuts = desc.midiOuts;
  137. info.parameterIns = desc.paramIns;
  138. info.parameterOuts = desc.paramOuts;
  139. info.name = desc.name;
  140. info.label = desc.label;
  141. info.maker = desc.maker;
  142. info.copyright = desc.copyright;
  143. return &info;
  144. }
  145. // -------------------------------------------------------------------------------------------------------------------
  146. static const CarlaCachedPluginInfo* get_cached_plugin_lv2(Lv2WorldClass& lv2World, Lilv::Plugin& lilvPlugin)
  147. {
  148. static CarlaCachedPluginInfo info;
  149. info.valid = false;
  150. bool supported = true;
  151. // ----------------------------------------------------------------------------------------------------------------
  152. // text data
  153. {
  154. static CarlaString suri, sname, smaker, slicense;
  155. suri.clear(); sname.clear(); smaker.clear(); slicense.clear();
  156. suri = lilvPlugin.get_uri().as_uri();
  157. if (char* const bundle = lilv_file_uri_parse(lilvPlugin.get_bundle_uri().as_uri(), nullptr))
  158. {
  159. water::File fbundle(bundle);
  160. lilv_free(bundle);
  161. suri = (fbundle.getFileName() + CARLA_OS_SEP).toRawUTF8() + suri;
  162. }
  163. else
  164. {
  165. suri = CARLA_OS_SEP_STR + suri;
  166. }
  167. #if 0 // def HAVE_FLUIDSYNTH
  168. // If we have fluidsynth support built-in, loading these plugins will lead to issues
  169. if (suri == "urn:ardour:a-fluidsynth")
  170. return &info;
  171. if (suri == "http://calf.sourceforge.net/plugins/Fluidsynth")
  172. return &info;
  173. #endif
  174. if (LilvNode* const nameNode = lilv_plugin_get_name(lilvPlugin.me))
  175. {
  176. if (const char* const name = lilv_node_as_string(nameNode))
  177. sname = name;
  178. lilv_node_free(nameNode);
  179. }
  180. if (LilvNode* const authorNode = lilv_plugin_get_author_name(lilvPlugin.me))
  181. {
  182. if (const char* const author = lilv_node_as_string(authorNode))
  183. smaker = author;
  184. lilv_node_free(authorNode);
  185. }
  186. Lilv::Nodes licenseNodes(lilvPlugin.get_value(lv2World.doap_license));
  187. if (licenseNodes.size() > 0)
  188. {
  189. if (LilvNode* const licenseNode = lilv_nodes_get_first(licenseNodes.me))
  190. {
  191. if (const char* const license = lilv_node_as_string(licenseNode))
  192. slicense = license;
  193. // lilv_node_free(licenseNode);
  194. }
  195. }
  196. lilv_nodes_free(const_cast<LilvNodes*>(licenseNodes.me));
  197. info.name = sname.buffer();
  198. info.label = suri.buffer();
  199. info.maker = smaker.buffer();
  200. info.copyright = slicense.buffer();
  201. }
  202. // ----------------------------------------------------------------------------------------------------------------
  203. // features
  204. info.hints = 0x0;
  205. {
  206. Lilv::UIs lilvUIs(lilvPlugin.get_uis());
  207. if (lilvUIs.size() > 0)
  208. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  209. #ifdef CARLA_OS_LINUX
  210. else if (lilvPlugin.get_modgui_resources_directory().as_uri() != nullptr)
  211. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  212. #endif
  213. lilv_nodes_free(const_cast<LilvNodes*>(lilvUIs.me));
  214. }
  215. {
  216. Lilv::Nodes lilvRequiredFeatureNodes(lilvPlugin.get_required_features());
  217. LILV_FOREACH(nodes, it, lilvRequiredFeatureNodes)
  218. {
  219. Lilv::Node lilvFeatureNode(lilvRequiredFeatureNodes.get(it));
  220. const char* const featureURI(lilvFeatureNode.as_uri());
  221. CARLA_SAFE_ASSERT_CONTINUE(featureURI != nullptr);
  222. if (! is_lv2_feature_supported(featureURI))
  223. {
  224. if (std::strcmp(featureURI, LV2_DATA_ACCESS_URI) == 0
  225. || std::strcmp(featureURI, LV2_INSTANCE_ACCESS_URI) == 0)
  226. {
  227. // we give a warning about this below
  228. continue;
  229. }
  230. supported = false;
  231. carla_stderr("LV2 plugin '%s' requires unsupported feature '%s'", info.label, featureURI);
  232. }
  233. }
  234. lilv_nodes_free(const_cast<LilvNodes*>(lilvRequiredFeatureNodes.me));
  235. }
  236. {
  237. Lilv::Nodes lilvSupportedFeatureNodes(lilvPlugin.get_supported_features());
  238. LILV_FOREACH(nodes, it, lilvSupportedFeatureNodes)
  239. {
  240. Lilv::Node lilvFeatureNode(lilvSupportedFeatureNodes.get(it));
  241. const char* const featureURI(lilvFeatureNode.as_uri());
  242. CARLA_SAFE_ASSERT_CONTINUE(featureURI != nullptr);
  243. /**/ if (std::strcmp(featureURI, LV2_CORE__hardRTCapable) == 0)
  244. {
  245. info.hints |= CB::PLUGIN_IS_RTSAFE;
  246. }
  247. else if (std::strcmp(featureURI, LV2_INLINEDISPLAY__queue_draw) == 0)
  248. {
  249. info.hints |= CB::PLUGIN_HAS_INLINE_DISPLAY;
  250. }
  251. else if (std::strcmp(featureURI, LV2_DATA_ACCESS_URI) == 0
  252. || std::strcmp(featureURI, LV2_INSTANCE_ACCESS_URI) == 0)
  253. {
  254. carla_stderr("LV2 plugin '%s' DSP wants UI feature '%s', ignoring this", info.label, featureURI);
  255. }
  256. }
  257. lilv_nodes_free(const_cast<LilvNodes*>(lilvSupportedFeatureNodes.me));
  258. }
  259. // ----------------------------------------------------------------------------------------------------------------
  260. // category
  261. info.category = CB::PLUGIN_CATEGORY_NONE;
  262. {
  263. Lilv::Nodes typeNodes(lilvPlugin.get_value(lv2World.rdf_type));
  264. if (typeNodes.size() > 0)
  265. {
  266. if (typeNodes.contains(lv2World.class_allpass))
  267. info.category = CB::PLUGIN_CATEGORY_FILTER;
  268. if (typeNodes.contains(lv2World.class_amplifier))
  269. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  270. if (typeNodes.contains(lv2World.class_analyzer))
  271. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  272. if (typeNodes.contains(lv2World.class_bandpass))
  273. info.category = CB::PLUGIN_CATEGORY_FILTER;
  274. if (typeNodes.contains(lv2World.class_chorus))
  275. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  276. if (typeNodes.contains(lv2World.class_comb))
  277. info.category = CB::PLUGIN_CATEGORY_FILTER;
  278. if (typeNodes.contains(lv2World.class_compressor))
  279. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  280. if (typeNodes.contains(lv2World.class_constant))
  281. info.category = CB::PLUGIN_CATEGORY_OTHER;
  282. if (typeNodes.contains(lv2World.class_converter))
  283. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  284. if (typeNodes.contains(lv2World.class_delay))
  285. info.category = CB::PLUGIN_CATEGORY_DELAY;
  286. if (typeNodes.contains(lv2World.class_distortion))
  287. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  288. if (typeNodes.contains(lv2World.class_dynamics))
  289. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  290. if (typeNodes.contains(lv2World.class_eq))
  291. info.category = CB::PLUGIN_CATEGORY_EQ;
  292. if (typeNodes.contains(lv2World.class_envelope))
  293. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  294. if (typeNodes.contains(lv2World.class_expander))
  295. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  296. if (typeNodes.contains(lv2World.class_filter))
  297. info.category = CB::PLUGIN_CATEGORY_FILTER;
  298. if (typeNodes.contains(lv2World.class_flanger))
  299. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  300. if (typeNodes.contains(lv2World.class_function))
  301. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  302. if (typeNodes.contains(lv2World.class_gate))
  303. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  304. if (typeNodes.contains(lv2World.class_generator))
  305. info.category = CB::PLUGIN_CATEGORY_OTHER;
  306. if (typeNodes.contains(lv2World.class_highpass))
  307. info.category = CB::PLUGIN_CATEGORY_FILTER;
  308. if (typeNodes.contains(lv2World.class_limiter))
  309. info.category = CB::PLUGIN_CATEGORY_DYNAMICS;
  310. if (typeNodes.contains(lv2World.class_lowpass))
  311. info.category = CB::PLUGIN_CATEGORY_FILTER;
  312. if (typeNodes.contains(lv2World.class_mixer))
  313. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  314. if (typeNodes.contains(lv2World.class_modulator))
  315. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  316. if (typeNodes.contains(lv2World.class_multiEQ))
  317. info.category = CB::PLUGIN_CATEGORY_EQ;
  318. if (typeNodes.contains(lv2World.class_oscillator))
  319. info.category = CB::PLUGIN_CATEGORY_OTHER;
  320. if (typeNodes.contains(lv2World.class_paraEQ))
  321. info.category = CB::PLUGIN_CATEGORY_EQ;
  322. if (typeNodes.contains(lv2World.class_phaser))
  323. info.category = CB::PLUGIN_CATEGORY_MODULATOR;
  324. if (typeNodes.contains(lv2World.class_pitch))
  325. info.category = CB::PLUGIN_CATEGORY_OTHER;
  326. if (typeNodes.contains(lv2World.class_reverb))
  327. info.category = CB::PLUGIN_CATEGORY_DELAY;
  328. if (typeNodes.contains(lv2World.class_simulator))
  329. info.category = CB::PLUGIN_CATEGORY_OTHER;
  330. if (typeNodes.contains(lv2World.class_spatial))
  331. info.category = CB::PLUGIN_CATEGORY_OTHER;
  332. if (typeNodes.contains(lv2World.class_spectral))
  333. info.category = CB::PLUGIN_CATEGORY_OTHER;
  334. if (typeNodes.contains(lv2World.class_utility))
  335. info.category = CB::PLUGIN_CATEGORY_UTILITY;
  336. if (typeNodes.contains(lv2World.class_waveshaper))
  337. info.category = CB::PLUGIN_CATEGORY_DISTORTION;
  338. if (typeNodes.contains(lv2World.class_instrument))
  339. {
  340. info.category = CB::PLUGIN_CATEGORY_SYNTH;
  341. info.hints |= CB::PLUGIN_IS_SYNTH;
  342. }
  343. }
  344. lilv_nodes_free(const_cast<LilvNodes*>(typeNodes.me));
  345. }
  346. // ----------------------------------------------------------------------------------------------------------------
  347. // number data
  348. info.audioIns = 0;
  349. info.audioOuts = 0;
  350. info.cvIns = 0;
  351. info.cvOuts = 0;
  352. info.midiIns = 0;
  353. info.midiOuts = 0;
  354. info.parameterIns = 0;
  355. info.parameterOuts = 0;
  356. for (uint i=0, count=lilvPlugin.get_num_ports(); i<count; ++i)
  357. {
  358. Lilv::Port lilvPort(lilvPlugin.get_port_by_index(i));
  359. bool isInput;
  360. /**/ if (lilvPort.is_a(lv2World.port_input))
  361. {
  362. isInput = true;
  363. }
  364. else if (lilvPort.is_a(lv2World.port_output))
  365. {
  366. isInput = false;
  367. }
  368. else
  369. {
  370. const LilvNode* const symbolNode = lilvPort.get_symbol();
  371. CARLA_SAFE_ASSERT_CONTINUE(symbolNode != nullptr && lilv_node_is_string(symbolNode));
  372. const char* const symbol = lilv_node_as_string(symbolNode);
  373. CARLA_SAFE_ASSERT_CONTINUE(symbol != nullptr);
  374. carla_stderr("LV2 plugin '%s' port '%s' is neither input or output", info.label, symbol);
  375. continue;
  376. }
  377. /**/ if (lilvPort.is_a(lv2World.port_control))
  378. {
  379. // skip some control ports
  380. if (lilvPort.has_property(lv2World.reportsLatency))
  381. continue;
  382. if (LilvNode* const designationNode = lilv_port_get(lilvPort.parent, lilvPort.me, lv2World.designation.me))
  383. {
  384. bool skip = false;
  385. if (const char* const designation = lilv_node_as_string(designationNode))
  386. {
  387. /**/ if (std::strcmp(designation, LV2_CORE__control) == 0)
  388. skip = true;
  389. else if (std::strcmp(designation, LV2_CORE__freeWheeling) == 0)
  390. skip = true;
  391. else if (std::strcmp(designation, LV2_CORE__latency) == 0)
  392. skip = true;
  393. else if (std::strcmp(designation, LV2_PARAMETERS__sampleRate) == 0)
  394. skip = true;
  395. else if (std::strcmp(designation, LV2_TIME__bar) == 0)
  396. skip = true;
  397. else if (std::strcmp(designation, LV2_TIME__barBeat) == 0)
  398. skip = true;
  399. else if (std::strcmp(designation, LV2_TIME__beat) == 0)
  400. skip = true;
  401. else if (std::strcmp(designation, LV2_TIME__beatUnit) == 0)
  402. skip = true;
  403. else if (std::strcmp(designation, LV2_TIME__beatsPerBar) == 0)
  404. skip = true;
  405. else if (std::strcmp(designation, LV2_TIME__beatsPerMinute) == 0)
  406. skip = true;
  407. else if (std::strcmp(designation, LV2_TIME__frame) == 0)
  408. skip = true;
  409. else if (std::strcmp(designation, LV2_TIME__framesPerSecond) == 0)
  410. skip = true;
  411. else if (std::strcmp(designation, LV2_TIME__speed) == 0)
  412. skip = true;
  413. else if (std::strcmp(designation, LV2_KXSTUDIO_PROPERTIES__TimePositionTicksPerBeat) == 0)
  414. skip = true;
  415. }
  416. lilv_node_free(designationNode);
  417. if (skip)
  418. continue;
  419. }
  420. if (isInput)
  421. ++(info.parameterIns);
  422. else
  423. ++(info.parameterOuts);
  424. }
  425. else if (lilvPort.is_a(lv2World.port_audio))
  426. {
  427. if (isInput)
  428. ++(info.audioIns);
  429. else
  430. ++(info.audioOuts);
  431. }
  432. else if (lilvPort.is_a(lv2World.port_cv))
  433. {
  434. if (isInput)
  435. ++(info.cvIns);
  436. else
  437. ++(info.cvOuts);
  438. }
  439. else if (lilvPort.is_a(lv2World.port_atom))
  440. {
  441. Lilv::Nodes supportNodes(lilvPort.get_value(lv2World.atom_supports));
  442. for (LilvIter *it = lilv_nodes_begin(supportNodes.me); ! lilv_nodes_is_end(supportNodes.me, it); it = lilv_nodes_next(supportNodes.me, it))
  443. {
  444. const Lilv::Node node(lilv_nodes_get(supportNodes.me, it));
  445. CARLA_SAFE_ASSERT_CONTINUE(node.is_uri());
  446. if (node.equals(lv2World.midi_event))
  447. {
  448. if (isInput)
  449. ++(info.midiIns);
  450. else
  451. ++(info.midiOuts);
  452. }
  453. }
  454. lilv_nodes_free(const_cast<LilvNodes*>(supportNodes.me));
  455. }
  456. else if (lilvPort.is_a(lv2World.port_event))
  457. {
  458. if (lilvPort.supports_event(lv2World.midi_event))
  459. {
  460. if (isInput)
  461. ++(info.midiIns);
  462. else
  463. ++(info.midiOuts);
  464. }
  465. }
  466. else if (lilvPort.is_a(lv2World.port_midi))
  467. {
  468. if (isInput)
  469. ++(info.midiIns);
  470. else
  471. ++(info.midiOuts);
  472. }
  473. else
  474. {
  475. const LilvNode* const symbolNode = lilvPort.get_symbol();
  476. CARLA_SAFE_ASSERT_CONTINUE(symbolNode != nullptr && lilv_node_is_string(symbolNode));
  477. const char* const symbol = lilv_node_as_string(symbolNode);
  478. CARLA_SAFE_ASSERT_CONTINUE(symbol != nullptr);
  479. supported = false;
  480. carla_stderr("LV2 plugin '%s' port '%s' is required but has unsupported type", info.label, symbol);
  481. }
  482. }
  483. if (supported)
  484. info.valid = true;
  485. return &info;
  486. }
  487. // -------------------------------------------------------------------------------------------------------------------
  488. #if defined(USING_JUCE) && defined(CARLA_OS_MAC)
  489. static juce::StringArray gCachedAuPluginResults;
  490. static void findAUs()
  491. {
  492. if (gCachedAuPluginResults.size() != 0)
  493. return;
  494. juce::AudioUnitPluginFormat auFormat;
  495. gCachedAuPluginResults = auFormat.searchPathsForPlugins(juce::FileSearchPath(), false, false);
  496. }
  497. static const CarlaCachedPluginInfo* get_cached_plugin_au(const juce::String pluginId)
  498. {
  499. static CarlaCachedPluginInfo info;
  500. static CarlaString sname, slabel, smaker;
  501. info.valid = false;
  502. juce::AudioUnitPluginFormat auFormat;
  503. juce::OwnedArray<juce::PluginDescription> results;
  504. auFormat.findAllTypesForFile(results, pluginId);
  505. CARLA_SAFE_ASSERT_RETURN(results.size() > 0, &info);
  506. CARLA_SAFE_ASSERT(results.size() == 1);
  507. juce::PluginDescription* const desc(results[0]);
  508. CARLA_SAFE_ASSERT_RETURN(desc != nullptr, &info);
  509. info.category = CB::getPluginCategoryFromName(desc->category.toRawUTF8());
  510. info.hints = 0x0;
  511. info.valid = true;
  512. if (desc->isInstrument)
  513. info.hints |= CB::PLUGIN_IS_SYNTH;
  514. if (true)
  515. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  516. info.audioIns = static_cast<uint32_t>(desc->numInputChannels);
  517. info.audioOuts = static_cast<uint32_t>(desc->numOutputChannels);
  518. info.cvIns = 0;
  519. info.cvOuts = 0;
  520. info.midiIns = desc->isInstrument ? 1 : 0;
  521. info.midiOuts = 0;
  522. info.parameterIns = 0;
  523. info.parameterOuts = 0;
  524. sname = desc->name.toRawUTF8();
  525. slabel = desc->fileOrIdentifier.toRawUTF8();
  526. smaker = desc->manufacturerName.toRawUTF8();
  527. info.name = sname;
  528. info.label = slabel;
  529. info.maker = smaker;
  530. info.copyright = gCachedPluginsNullCharPtr;
  531. return &info;
  532. }
  533. #endif
  534. // -------------------------------------------------------------------------------------------------------------------
  535. static const CarlaCachedPluginInfo* get_cached_plugin_sfz(const water::File& file)
  536. {
  537. static CarlaCachedPluginInfo info;
  538. static CarlaString name, filename;
  539. name = file.getFileNameWithoutExtension().toRawUTF8();
  540. name.replace('_',' ');
  541. filename = file.getFullPathName().toRawUTF8();
  542. info.category = CB::PLUGIN_CATEGORY_SYNTH;
  543. info.hints = CB::PLUGIN_IS_SYNTH;
  544. // CB::PLUGIN_IS_RTSAFE
  545. info.valid = true;
  546. info.audioIns = 0;
  547. info.audioOuts = 2;
  548. info.cvIns = 0;
  549. info.cvOuts = 0;
  550. info.midiIns = 1;
  551. info.midiOuts = 0;
  552. info.parameterIns = 0;
  553. info.parameterOuts = 1;
  554. info.name = name.buffer();
  555. info.label = filename.buffer();
  556. info.maker = gCachedPluginsNullCharPtr;
  557. info.copyright = gCachedPluginsNullCharPtr;
  558. return &info;
  559. }
  560. // -------------------------------------------------------------------------------------------------------------------
  561. #ifdef HAVE_YSFX
  562. static const CarlaCachedPluginInfo* get_cached_plugin_jsfx(const CB::CarlaJsfxUnit& unit)
  563. {
  564. static CarlaCachedPluginInfo info;
  565. ysfx_config_u config(ysfx_config_new());
  566. const water::String rootPath = unit.getRootPath();
  567. const water::String filePath = unit.getFilePath();
  568. ysfx_register_builtin_audio_formats(config.get());
  569. ysfx_set_import_root(config.get(), rootPath.toRawUTF8());
  570. ysfx_guess_file_roots(config.get(), filePath.toRawUTF8());
  571. ysfx_set_log_reporter(config.get(), &CB::CarlaJsfxLogging::logErrorsOnly);
  572. ysfx_u effect(ysfx_new(config.get()));
  573. if (! ysfx_load_file(effect.get(), filePath.toRawUTF8(), 0))
  574. {
  575. info.valid = false;
  576. return &info;
  577. }
  578. // plugins with neither @block nor @sample are valid, but they are useless
  579. // also use this as a sanity check against misdetected files
  580. // since JSFX parsing is so permissive, it might accept lambda text files
  581. if (! ysfx_has_section(effect.get(), ysfx_section_block) &&
  582. ! ysfx_has_section(effect.get(), ysfx_section_sample))
  583. {
  584. info.valid = false;
  585. return &info;
  586. }
  587. static CarlaString name, label, maker;
  588. label = unit.getFileId().toRawUTF8();
  589. name = ysfx_get_name(effect.get());
  590. maker = ysfx_get_author(effect.get());
  591. info.valid = true;
  592. info.category = CB::CarlaJsfxCategories::getFromEffect(effect.get());
  593. info.audioIns = ysfx_get_num_inputs(effect.get());
  594. info.audioOuts = ysfx_get_num_outputs(effect.get());
  595. info.cvIns = 0;
  596. info.cvOuts = 0;
  597. info.midiIns = 1;
  598. info.midiOuts = 1;
  599. info.parameterIns = 0;
  600. info.parameterOuts = 0;
  601. for (uint32_t sliderIndex = 0; sliderIndex < ysfx_max_sliders; ++sliderIndex)
  602. {
  603. if (ysfx_slider_exists(effect.get(), sliderIndex))
  604. ++info.parameterIns;
  605. }
  606. info.hints = 0;
  607. #if 0 // TODO(jsfx) when supporting custom graphics
  608. if (ysfx_has_section(effect.get(), ysfx_section_gfx))
  609. info.hints |= CB::PLUGIN_HAS_CUSTOM_UI;
  610. #endif
  611. info.name = name.buffer();
  612. info.label = label.buffer();
  613. info.maker = maker.buffer();
  614. info.copyright = gCachedPluginsNullCharPtr;
  615. return &info;
  616. }
  617. #endif
  618. // -------------------------------------------------------------------------------------------------------------------
  619. uint carla_get_cached_plugin_count(CB::PluginType ptype, const char* pluginPath)
  620. {
  621. CARLA_SAFE_ASSERT_RETURN(isCachedPluginType(ptype), 0);
  622. carla_debug("carla_get_cached_plugin_count(%i:%s, %s)", ptype, CB::PluginType2Str(ptype), pluginPath);
  623. switch (ptype)
  624. {
  625. case CB::PLUGIN_INTERNAL: {
  626. uint32_t count = 0;
  627. carla_get_native_plugins_data(&count);
  628. return count;
  629. }
  630. case CB::PLUGIN_LV2: {
  631. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  632. lv2World.initIfNeeded(pluginPath);
  633. return lv2World.getPluginCount();
  634. }
  635. #if defined(USING_JUCE) && defined(CARLA_OS_MAC)
  636. case CB::PLUGIN_AU: {
  637. findAUs();
  638. return static_cast<uint>(gCachedAuPluginResults.size());
  639. }
  640. #endif
  641. case CB::PLUGIN_SFZ: {
  642. findSFZs(pluginPath);
  643. return static_cast<uint>(gSFZs.size());
  644. }
  645. #ifdef HAVE_YSFX
  646. case CB::PLUGIN_JSFX: {
  647. findJSFXs(pluginPath);
  648. return static_cast<uint>(gJSFXs.size());
  649. }
  650. #endif
  651. default:
  652. return 0;
  653. }
  654. }
  655. const CarlaCachedPluginInfo* carla_get_cached_plugin_info(CB::PluginType ptype, uint index)
  656. {
  657. carla_debug("carla_get_cached_plugin_info(%i:%s, %i)", ptype, CB::PluginType2Str(ptype), index);
  658. switch (ptype)
  659. {
  660. case CB::PLUGIN_INTERNAL: {
  661. uint32_t count = 0;
  662. const NativePluginDescriptor* const descs(carla_get_native_plugins_data(&count));
  663. CARLA_SAFE_ASSERT_BREAK(index < count);
  664. CARLA_SAFE_ASSERT_BREAK(descs != nullptr);
  665. const NativePluginDescriptor& desc(descs[index]);
  666. return get_cached_plugin_internal(desc);
  667. }
  668. case CB::PLUGIN_LV2: {
  669. Lv2WorldClass& lv2World(Lv2WorldClass::getInstance());
  670. const LilvPlugin* const cPlugin(lv2World.getPluginFromIndex(index));
  671. CARLA_SAFE_ASSERT_BREAK(cPlugin != nullptr);
  672. Lilv::Plugin lilvPlugin(cPlugin);
  673. CARLA_SAFE_ASSERT_BREAK(lilvPlugin.get_uri().is_uri());
  674. return get_cached_plugin_lv2(lv2World, lilvPlugin);
  675. }
  676. #if defined(USING_JUCE) && defined(CARLA_OS_MAC)
  677. case CB::PLUGIN_AU: {
  678. CARLA_SAFE_ASSERT_BREAK(index < static_cast<uint>(gCachedAuPluginResults.size()));
  679. return get_cached_plugin_au(gCachedAuPluginResults.strings.getUnchecked(static_cast<int>(index)));
  680. }
  681. #endif
  682. case CB::PLUGIN_SFZ: {
  683. CARLA_SAFE_ASSERT_BREAK(index < gSFZs.size());
  684. return get_cached_plugin_sfz(gSFZs[index]);
  685. }
  686. #ifdef HAVE_YSFX
  687. case CB::PLUGIN_JSFX: {
  688. CARLA_SAFE_ASSERT_BREAK(index < static_cast<uint>(gJSFXs.size()));
  689. return get_cached_plugin_jsfx(gJSFXs[index]);
  690. }
  691. #endif
  692. default:
  693. break;
  694. }
  695. static CarlaCachedPluginInfo info;
  696. return &info;
  697. }
  698. // -------------------------------------------------------------------------------------------------------------------
  699. #ifndef CARLA_PLUGIN_BUILD
  700. # include "../native-plugins/_data.cpp"
  701. #endif
  702. // -------------------------------------------------------------------------------------------------------------------