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.

827 lines
28KB

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