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.

861 lines
29KB

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