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.

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