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.

844 lines
29KB

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