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.

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