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.

870 lines
30KB

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